<template>
    <div id="cashier" class="cashier" @click="goodList=[];addVipBtn=false;showSetWrap=false;">
        <div class="cashier_content">
            <div class="goods_box left">
                <div class="left" style="width:39%;height:100%;margin-right:2%;">
                    <div class="vipbox" :class="{heights:curSelectVipData}">
                        <!-- 会员信息框 -->
                        <div class="vip-info" :style="{display:curSelectVipData?'block':'none'}">
                            <span class="close-btn" @click="closeVipFn();deBindVip();">&times;</span>
                            <!-- <div class="space-height"></div> -->
                            <div class="up-vip" v-if="chainEnabled">
                                <span @click="upThisVip">升级该会员</span>
                                <!-- <i class="iconfont icon-wenhao" @click="showUpInfo=true"></i> -->
                            </div>
                            <div class="item clearfix name_recharge">
                                <span class="left vipname" v-text="curSelectVipData.name"></span>
                                <span class="left recharge" @click="showRechargeBox=true;vipPayBtn=false">会员充值</span>
                                <div class="right selCoupon">
                                    <span class="name" @click="openCoupon">{{curBindCoupon[0]?curBindCoupon.length+'张优惠券':'选择优惠券'}}</span>
                                    <div class="curCouponBox" :style="{top:(-(curBindCoupon.length*30+10)/2+'px')}" v-if="curBindCoupon[0]">
                                        <li v-for="(item,idx) in curBindCoupon">
                                            <div class="left couponMsg" :title="item.couponName+'  商品抵用券 - '+item.productName">
                                                <span class="couponName" v-text="item.couponName"></span>
                                                <span v-text="'商品抵用券'"></span>
                                                <span>-</span>
                                                <span v-text="item.productName"></span>
                                            </div>
                                            <span class="right deBind" @click="relieveCoupon(item)">&times;</span>
                                        </li>
                                    </div>
                                </div>
                            </div>
                            <div class="space-height"></div>
                            <div class="item clearfix phone_price"><span class="left" v-text="curSelectVipData.mobile?curSelectVipData.mobile:curSelectVipData.code"></span><span class="right price" v-text="'￥'+curSelectVipData.amount"></span></div>
                            <div class="space-height"></div>
                        </div>
                        <!-- 选择会员内容框 -->
                        <div class="vip_up" :style="{display:(addVipBtn?'block':'none')}" @click.stop="">
                            <div class="closeBtn userNotSelect" @click="addVipBtn=false;">&times;</div>
                            <div class="vipInputBox flex flex-align-center">
                                <input type="text" class="vipInput" v-model="vipNumber" placeholder="输入会员账号">
                                <!-- <button type="button" @click="addVipFn">确认</button> -->
                            </div>
                            <ul class="vipCheckList">
                                <div class="leftIcon" :style="{top:(curVipIdx*40+'px'),display:(vipList[0]?'block':'none')}"></div>
                                <li v-for="item in vipList" @click.stop="addVipFn(item)">
                                    <div class="left name" v-text="item.name" :title="item.name"></div>
                                    <div class="right tel" v-text="item.mobile?item.mobile:item.code"></div>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class="goods_order">
                        <div class="add-vip-btn" :style="{display:curSelectVipData?'none':'block'}">
                            <button class="vip_btn" type="button" @click.stop="vipNumber='';addVipBtn=!addVipBtn;vipList=[]">
                            <!-- <button class="vip_btn" type="button" @click.stop="payVoice('success',0.01)"> -->
                                选择会员
                            </button>
                        </div>
                        <div class="scroll_out_box">
                            <div class="scroll_box">
                                <div class="scroll_inner_box">
                                    <div class="goods_order_item" v-for="(item,ind) in choiceArr">
                                        <p class="title_name ellipsis" :title="item.productName">
                                            {{item.productName}}
                                            <el-tooltip class="item" effect="dark" 
                                            v-if="item.isDiscountForSecond"
                                            :content="`参与折扣数量：${item.discountForSecondQty}份`" 
                                            placement="top-start">
                                                <i style="color:red;cursor:pointer;padding-left:10px" class="iconfont icon-wenhao1"></i>
                                            </el-tooltip>
                                        </p>
                                        <!-- 规格start -->
                                        <div class="spec-info" v-if="item.specs && Array.isArray(item.specs) && item.specs.length">
                                            规格：<span class="tag" v-for="(it,ind) in item.specs" :key="ind">{{it}}</span>
                                        </div>
                                        <!-- 规格end -->
                                        <div class="money_number clearfix" v-if="item.productName">
                                            <div class="left money">{{'&yen;'+(item.salesPrice/item.quantity).toFixed(2)}}</div>
                                            <div class="right number clearfix">
                                                <span class="number_reduction left userNotSelect" @click="reduceAmount(item)">-</span>
                                                <span class="amount left" v-text="item.quantity"></span>
                                                <span class="number_add left userNotSelect" @click="addAmount(item)">+</span>
                                                <span class="multi-count" @click="doShowMultiCount(item)">批量</span>
                                                <span class="multi-count" v-if="item.matchEnabled" @click="doShowPeiGoods(item)">配</span>
                                            </div>
                                        </div>
                                        <div class="sub-items" v-if="item.masterItemDtos && Array.isArray(item.masterItemDtos) && item.masterItemDtos.length">
                                            <div class="sub-item" v-for="(it,ind) in item.masterItemDtos" :key="ind">
                                                <p class="title_name ellipsis" :title="it.productName" v-if="it.productName">
                                                    <i class="pei">配</i>{{it.productName}}
                                                </p>
                                                <div class="money_number clearfix" v-if="it.productName">
                                                    <div class="left money">{{'&yen;'+(it.salesPrice/it.quantity).toFixed(2)}}</div>
                                                    <div class="right number clearfix">
                                                        <span class="number_reduction left userNotSelect" @click="reduceAmountForPei(it,item)">-</span>
                                                        <span class="amount left" v-text="it.quantity"></span>
                                                        <span class="number_add left userNotSelect" @click="addAmountForPei(item,it)">+</span>
                                                    </div>
                                                </div>
                                            </div>
                                            
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="pay_box">
                            <div class="pay_li">
                                <div class="left flex flex-align-center">
                                    <span class="name">合计</span>
                                    <span class="number red" v-text="'￥'+totalPrice.total.toFixed(2)"></span>
                                </div>
                                <div class="right flex flex-align-center">
                                    <span class="name">总数</span>
                                    <span class="number" v-text="totalPrice.count"></span>
                                </div>
                            </div>
                            <div class="pay_li">
                                <div class="left flex flex-align-center red">
                                    <span class="name">优惠</span>
                                    <span class="number" v-text="'￥'+(totalPrice.discount).toFixed(2)"></span>
                                </div>
                                <!-- <div class="left flex flex-align-center red">
                                    <span class="name">抹零</span>
                                    <span class="number" v-text="'￥'+(totalPrice.removeZero).toFixed(2)"></span>
                                </div> -->
                            </div>
                            <div class="pay_li">
                                <div class="left flex flex-align-center red">
                                    <span class="name">应付</span>
                                    <span class="number bigSize" v-text="'￥'+totalPrice.amount.toFixed(2)"></span>
                                </div>
                            </div>
                            <div class="pay_li">
                                <div class="left flex flex-align-center red">
                                    <span class="number" v-text="(curSelectVipData&&curSelectVipData.amount>=totalPrice.amount)?'可用会员余额支付结账':((curSelectVipData.amount<totalPrice.amount)?'会员余额不足，请提醒充值':'')">应付</span>
                                </div>
                            </div>
                            <!-- <div class="ready_order">
                                <button  type="button" class="right">挂单</button>
                            </div> -->
                            <div class="btnGroup">
                                <button class="delOrder" type="button" @click="showConfirmMask=true;">撤销</button>
                                <button class="pay_btn" type="button" @click="shopUpBox(true)">结账</button>
                            </div>
                        </div>
                        <div class="up_box" :class="{move_animation:upBtn}">
                            <div class="top_money">
                                <div class="returnBtn">
                                    <div class="left flex flex-align-center" @click="shopUpBoxForReturnMoney(false)">
                                        <i class="iconfont icon-fanhui"></i>
                                        <span>返回</span>
                                    </div>
                                </div>
                                <div class="totalPrice flex flex-align-center flex-pack-center" v-text="'￥'+totalPrice.amount.toFixed(2)"></div>
                                <div class="serialNumber flex flex-align-center">
                                    <span class="name">流水号</span>
                                    <span v-text="code"></span>
                                </div>
                            </div>
                            
                            <p class="selPayType flex flex-align-center">选择支付方式</p>
                            <!-- <div class="pay_type clearfix">
                                <span class="left size1" @click="changePayType('CASH')" v-if="!curSelectVipData" :class="{span_active:payType == 'CASH'}">现金支付</span>
                                <span v-if="isOnline && !curSelectVipData" class="left size1" @click="openPayCodeBox('PAYCARD')" :class="{span_active:payType == 'PAYCARD'}">在线支付</span>

                                <span v-if="!isOnline && !curSelectVipData" class="left size1" :class="{span_active:payType == 'ALIPAY_CASH'}"><input name="Fruit" type="radio" value="ALIPAY_CASH" v-model="payType">支付宝支付</span>
                                <span v-if="!isOnline && !curSelectVipData" class="left size1" :class="{span_active:payType == 'WECHATPAY_CASH'}"><input name="Fruit" type="radio" value="WECHATPAY_CASH" v-model="payType">微信支付</span>

                                <span class="left size1" :class="{span_active:payType == 'MEMBER'}" v-if="curSelectVipData&&(curSelectVipData.amount>=totalPrice.amount)" @click="changePayType('MEMBER')">会员支付</span>
                                <p style="color:red;" v-if="(curSelectVipData.amount<totalPrice.amount)" v-text="(curSelectVipData.amount<totalPrice.amount)?'会员余额不足，请充值。':''"></p>
                                
                            </div> -->
                            <div class="pay_type clearfix">
                                <span class="left size1" @click="changePayType('CASH')" :class="{span_active:payType == 'CASH'}">现金支付</span>
                                <span v-if="isOnline" class="left size1" @click="openPayCodeBox('PAYCARD')" :class="{span_active:payType == 'PAYCARD'}">在线支付</span>

                                <span v-if="!isOnline" class="left size1" :class="{span_active:payType == 'ALIPAY_CASH'}"><input name="Fruit" type="radio" value="ALIPAY_CASH" v-model="payType">支付宝支付</span>
                                <span v-if="!isOnline" class="left size1" :class="{span_active:payType == 'WECHATPAY_CASH'}"><input name="Fruit" type="radio" value="WECHATPAY_CASH" v-model="payType">微信支付</span>

                                <span class="left size1" :class="{span_active:payType == 'MEMBER'}" v-if="curSelectVipData&&(curSelectVipData.amount>=totalPrice.amount)" @click="changePayType('MEMBER')">会员支付</span>
                            </div>
                                <p style="color:red;padding:1% 5%" v-if="curSelectVipData && (curSelectVipData.amount<totalPrice.amount)" v-text="(curSelectVipData.amount<totalPrice.amount)?'会员余额不足，充值后可选择会员支付。':''"></p>
                            <div class="selPayType flex flex-align-center" style="height:5%;color:#e66a6a;font-size:16px;">
                                <span class="name">优惠:</span>
                                <span class="number" style="margin-right:10px;" v-text="'￥'+(totalPrice.discount).toFixed(2)"></span>
                                <span class="name">零头:</span>
                                <span class="number" v-text="'￥'+(totalPrice.removeZero).toFixed(2)"></span>
                            </div>
                            <div class="prints clearfix notes">
                                <div class="check left">
                                    <span>座位号</span>
                                </div>
                                <div class="input-num left">
                                    <input type="text" placeholder="输入座位号" v-model="tableNo">
                                </div>
                            </div>
                            <div class="prints clearfix notes" >
                                <div class="check left"  style="width:30%;">
                                    <span>备注</span>
                                    <span>(自选<input type="checkbox" v-model="selNotes">)</span>
                                </div>
                                <div class="input-num left" style="width:69%;">
                                    <input type="text" v-if="!selNotes" placeholder="请输入口味、偏好等要求" v-model="notes">
                                    <el-select v-if="selNotes" v-model="notes" placeholder="请选择">
                                        <el-option
                                        v-for="(item,index) in notesArr"
                                        :key="index"
                                        :value="item.message">
                                        </el-option>
                                    </el-select>
                                </div>
                            </div>
                            <div class="prints clearfix">
                                <div class="check left">
                                    <span>打印单据</span>
                                    <input type="checkbox" v-model="localPrintsBtn">
                                </div>
                                <div class="input-num left" v-if="localPrintsBtn">
                                    <input type="text" placeholder="输入打印份数" v-model="printsNum">
                                </div>
                            </div>
                            <div class="sure_pay">
                                <button @click="confirmPayment" type="button">确认支付</button>
                            </div>
                            <div v-if="showDiscount||showZero" :class="showSetWrap?'discount-wipe-zero show-set':'discount-wipe-zero'" @click.stop="" >
                                <div class="wrap">
                                    <div class="discount-set" v-if="showDiscount">
                                        <span>折扣:</span>
                                        <el-select v-model="firstDiscount" placeholder="请选择">
                                            <el-option
                                            v-for="item in discountVals"
                                            :key="item"
                                            :value="item">
                                            </el-option>
                                        </el-select>
                                        <el-select v-model="lastDiscount" placeholder="请选择">
                                            <el-option
                                            v-for="item in discountVals"
                                            :key="item"
                                            :value="item">
                                            </el-option>
                                        </el-select>
                                        <div class="now-discount">
                                            <span>当前所选折扣：<b>{{firstDiscount+'.'+lastDiscount}}</b> 折</span>
                                        </div>
                                        <div>
                                            <span>折后价：<b>{{Number(Number(firstDiscount+''+lastDiscount)/100) == 0?totalPrice.amount.toFixed(2):((totalPrice.amount)*Number(Number(firstDiscount+''+lastDiscount)/100)).toFixed(2)}}</b> 元</span>
                                        </div>
                                    </div>
                                    <!-- <div v-if="showZero" style="padding-bottom:10px;">
                                        <el-checkbox v-model="checkedWipeZero">抹零</el-checkbox>
                                    </div> -->
                                    <div v-if="showZero" style="padding-bottom:10px;" class="auto-money">
                                        <span class="money" style="font-size:14px;color:red;">自定义金额:</span>
                                        <input type="text" v-model="wipeZeroMoney" placeholder="请输入金额" />
                                    </div>
                                    <div class="sure-discount">
                                        <button @click="discountThisOrder">确定</button>
                                    </div>
                                    
                                    <!-- <div class="wipe-set" v-if="showZero">
                                        <button @click="wipeZero">抹零</button>
                                    </div> -->
                                </div>
                                <div class="trag-set" @click.stop="showPwd">
                                    <span>折扣 & 零头</span>
                                </div>
                            </div>
                        </div>
                        <div class="userPayCodeBox" v-if="showPayCodeBox">
                            <form class="userPayCode" @submit.prevent="confirmPayment">
                                <div class="tipText">
                                    * 请输入或者扫描用户付款码
                                </div>
                                <div class="inputBox">
                                    <input type="text" id="" v-focus autocomplete="off" v-model="payCode">
                                </div>
                                <div class="btnGroup">
                                    <button type="submit" class="save">确认</button>
                                    <button type="button" class="cancel" @click="showPayCodeBox=false">取消</button>
                                </div>
                            </form>
                        </div>
                        <!--  -->
                        <div class="userPayCodeBox" v-if="showPayCodeBoxForRent">
                            <form class="userPayCode" @submit.prevent="confirmPaymentForRent">
                                <div class="tipText">
                                    * 请输入或者扫描用户付款码
                                </div>
                                <div class="inputBox">
                                    <input type="text" id="" v-focus autocomplete="off" v-model="rentForm.authCode">
                                </div>
                                <div class="btnGroup">
                                    <button type="submit" class="save">确认</button>
                                    <button type="button" class="cancel" @click="showPayCodeBoxForRent=false">取消</button>
                                </div>
                            </form>
                        </div>
                        <!--  -->
                        <div class="payLoding" v-if="showPayLoding">
                            <div class="payLodeBox">
                                <div class="payLoadImg">
                                    <i class="iconfont icon-looding"></i>
                                </div>
                                <p v-if="payType == 'PAYCARD' || payVipType == 'PAYCARD'">支付中，请等待！</p>
                                <!-- <p v-if="payType == 'PAYCARD' || payVipType == 'PAYCARD'">请在3分钟内完成支付，超时将自动取消。</p> -->
                                <!-- <div class="btnGroup" v-if="payType == 'PAYCARD' || payVipType == 'PAYCARD'"> -->
                                    <!-- <button type="button"  @click="deletePayment(orderId)" :class="canDeletepayment?'cancel':'cancel wd'" v-text="canDeletepayment?'取消支付':('取消支付('+delPaymentLodingTime+'s)')"></button> -->
                                    <!-- <button type="button" class="save" @click="aNewOrder">挂起此单</button> -->
                                <!-- </div> -->
                            </div>
                        </div>
                        <!--  -->
                        <!-- <div v-if="showDiscount||showZero" :class="showSetWrap?'discount-wipe-zero show-set':'discount-wipe-zero'" @click.stop="" >
                            <div class="wrap">
                                <div class="discount-set" v-if="showDiscount">
                                    <span>折扣:</span>
                                    <el-select v-model="firstDiscount" placeholder="请选择">
                                        <el-option
                                        v-for="item in discountVals"
                                        :key="item"
                                        :value="item">
                                        </el-option>
                                    </el-select>
                                    <el-select v-model="lastDiscount" placeholder="请选择">
                                        <el-option
                                        v-for="item in discountVals"
                                        :key="item"
                                        :value="item">
                                        </el-option>
                                    </el-select>
                                    <div class="now-discount">
                                        <span>当前所选折扣：<b>{{firstDiscount+'.'+lastDiscount}}</b> 折</span>
                                    </div>
                                    <div class="sure-discount">
                                        <button @click="discountThisOrder">打折</button>
                                    </div>
                                </div>
                                <div class="wipe-set" v-if="showZero">
                                    <button @click="wipeZero">抹零</button>
                                </div>
                            </div>
                            <div class="trag-set" @click.stop="showPwd">
                                <span>折扣 & 抹零</span>
                            </div>
                        </div> -->
                        <!--  -->
                    </div>
                </div>
                <div class="goods_item_box left">
                    <div class="searchGood clearfix" @keyup.enter="choiceGoods(goodList[0])">
                        <i class="iconfont icon-sousuo sousuo"></i>
                        <input type="text" class="right" id="searchInput" v-model="goodSearch" placeholder="商品检索">
                        <ul class="goodCheckList" :style="{display:(goodList[0]?'block':'none')}" @click.stop="">
                            <div class="leftIcon" :style="{top:(curGoodIdx*40+'px')}"></div>
                            <li v-for="item in goodList" @click="choiceGoods(item);goodList=[]">
                                <div class="left name" v-text="item.name"></div>
                            </li>
                        </ul>
                    </div>
                    <div class="right_scroll_box">
                        <div class="scroll_inner_box">
                            <div class="goods_item" v-if="showMenu">
                                <div class="goods_item_inner_box clearfix">
                                    <div class="goods_li left" style="cursor:pointer;" v-for="(item,ind) in curSelectGoodsData.products" @click.stop="choiceGoods(item)">
                                        <div class="imgBox">
                                            <!-- <div class="inventoryNumber clearfix " :class="{'nowNotSupply':item.supplyTimes==='[]'||item.supplyTimes===null?false:true,'inventoryNumberSpace':item.productStatus=='ON'?false:true}"> -->
                                            <div class="inventoryNumber clearfix " style="display:flex;" :class="{'':doShowSupply(item.supplyTimes),'inventoryNumberSpace':item.productStatus=='ON'?false:true}">
                                                <span @click.stop="showpProductStatus(item)" v-if="item.id.length>4 && !item.leaseEnabled">
                                                        <span class="left"  v-text="item.productStatus=='ON'?'已上架':'已下架'"></span>
                                                <i class="iconfont icon-xialajiantou"></i>
                                                </span>
                                                <span v-if="item.leaseEnabled">
                                                    <span class="left" style="display:flex;flex-wrap: nowrap;white-space: nowrap;font-size:14px;">租赁商品</span>
                                                </span>
                                                <span class="ct right" v-if="!item.leaseEnabled" v-text="item.stockEnabled?'×'+item.quantity:'无限'"></span>
                                                <span class="ct right" v-if="item.leaseEnabled">×{{ item.quantity }}</span>
                                            </div>
                                            <div  class="imgBoxBottom">
                                                <p v-text="item.name" class="p" :style="item.leaseEnabled ? 'margin-top:20px' :'' " :title="item.name"></p>
                                                <p v-text=" '￥' + item.salesPrice" v-if="!item.leaseEnabled" class="p sales_price"></p>
                                                <!-- <p v-else class="p sales_price"></p> -->
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="goods_item"  v-if="showMenu" v-for="(item,ind) in curSelectGoodsData.subTypes">
                                <p v-text="item.typeName" class="title_name"></p>
                                <div class="goods_item_inner_box clearfix">
                                    <div class="goods_li left" v-for="oitem in curSelectGoodsData.subTypes[ind].products">
                                        <div class="imgBox">
                                            <!-- <div class="inventoryNumber clearfix" :class="{'nowNotSupply':oitem.supplyTimes==='[]'||oitem.supplyTimes===null?false:true,'inventoryNumberSpace':oitem.productStatus=='ON'?false:true}"> -->
                                            <div class="inventoryNumber clearfix" :class="{'':doShowSupply(oitem.supplyTimes),'inventoryNumberSpace':oitem.productStatus=='ON'?false:true}">
                                                <span @click="showpProductStatus(oitem)">
                                                        <span class="left" v-text="oitem.productStatus=='ON'?'已上架':'已下架'" ></span>
                                                <i class="iconfont icon-xialajiantou"></i>
                                                </span>
                                                <span class="ct right" v-text="oitem.stockEnabled?'×'+oitem.quantity:'无限'"></span>
                                            </div>
                                            <div @click="choiceGoods(oitem)" class="imgBoxBottom">
                                                <p v-text="oitem.name" class="p"></p>
                                                <p v-text=" '￥' + oitem.salesPrice" class="p sales_price"></p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="goods_type_nav left">
                <div class="scroll">
                    <div v-if="goodsData[0].typeName" class="nav_text" :class="{nav_text_active:curIdx==index}" v-for="(oitem,index) in goodsData" :key="index">
                        <span v-text="oitem.typeName" class="bigType left" @click="selGoodType(index)" :title="oitem.typeName"></span>
                        <span v-for="(item,idx) in oitem.subTypes" class="smallType left" @click="selSmallGoodType(index, idx)" v-text="item.typeName"></span>
                        <i v-if="curIdx==index&&curSmallTypeIdx>=0" class="iconfont icon-jiantou1" :style="{top:(70+curSmallTypeIdx*54)+'px'}"></i>
                    </div>
                </div>
            </div>
        </div>
        <div class="mask" v-if="showConfirmMask" @click="showConfirmMask=false">
            <div class="orderConfirmBox" @click.stop="">
                <div class="title">提示</div>
                <p>确认删除此单？</p>
                <div class="btnGroup">
                    <button type="button" class="cancel" @click="showConfirmMask=false">取消</button>
                    <button type="button" class="save" @click="delOrder">确认</button>
                </div>
            </div>
        </div>
        <div class="mask" v-if="productStatus.btn" @click="productStatus.btn=false">
            <div class="orderConfirmBox" @click.stop="">
                <div class="title">提示</div>
                <p>商品 <span style="color:red;height:103%;display:inline-block;vertical-align: middle;max-width: 150px;overflow: hidden; text-overflow: ellipsis;white-space: nowrap" :title="productStatus.name">{{productStatus.name}}</span> 将 <span style="color:red;">{{productStatus.status=='ON'?'下架':'上架'}}</span>，是否继续？</p>
                <div class="btnGroup">
                    <button type="button" class="cancel" @click="productStatus.btn=false">取消</button>
                    <button type="button" class="save" @click="sureProductStatus">确认</button>
                </div>
            </div>
        </div>
        <div class="mask" v-if="showCustomPrice" @click="showCustomPrice=false">
            <div class="customPriceBox" @click.stop="">
                <div class="title">自定义网费</div>
                <div class="inner">
                    <input type="text" id="customPriceInput" v-model="customPrice" placeholder="请输入自定义网费价格" @keyup.enter="confirmCustomPrice">
                </div>
                <div class="btnGroup">
                    <button type="button" class="cancel" @click="showCustomPrice=false">取消</button>
                    <button type="button" class="save" @click="confirmCustomPrice">确认</button>
                </div>
            </div>
        </div>
        <div class="mask" v-if="showOnLinePaySuccessMask" @click="showOnLinePaySuccessMask=false">
            <div class="orderConfirmBox" @click.stop="">
                <div class="title">提示</div>
                <p>支付成功！</p>
                <div class="btnGroup">
                    <button type="button" class="save" @click="showOnLinePaySuccessMask=false">确认</button>
                </div>
            </div>
        </div>
        <div class="vipRechargeMask" v-if="showRechargeBox" @click="showRechargeBox=false">
            <div class="vipRechargeBox" @click.stop="">
                <div class="title">会员充值</div>
                <div class="vipMsg clearfix">
                    <div class="name left">会员名称：</div>
                    <div class="val left" v-text="curSelectVipData.name"></div>
                    <div class="name left">会员帐号：</div>
                    <div class="val left" v-text="curSelectVipData.mobile?curSelectVipData.mobile:curSelectVipData.code"></div>
                </div>
                <div class="selMoneyBox">
                    <div class="recharge-scroll-box" v-if="!vipPayBtn">
                        <div class="item" v-for="item in rulesData" @click="choiceRules(item)"><span v-text="item.name"></span></div>
                        <div class="input-recharge">
                            <div class="clearfix">
                                <span class="left">自定义金额：</span>
                                <input class="left" type="text" placeholder="请输入充值金额" v-model="inputVipMoney">
                            </div>
                        </div>
                    </div>
                    <div class="btnGroup" v-if="!vipPayBtn">
                        <button type="button" class="cancel" @click="showRechargeBox=false">取消</button>
                        <button type="button" class="save" @click="choiceRules()">确认</button>
                    </div>
                    <div class="vipPayBox" v-if="vipPayBtn">
                        <div class="top_money">
                            <div class="returnBtn">
                                <div class="left flex flex-align-center" @click="vipPayBtn=false">
                                    <i class="iconfont icon-fanhui"></i>
                                    <span>返回</span>
                                </div>
                            </div>
                            <div class="totalPrice flex flex-align-center flex-pack-center" v-text="'￥'+(inputVipMoney?inputVipMoney:(vipObj.depositAmount?vipObj.depositAmount:0))"></div>
                            <div class="serialNumber flex flex-align-center">
                                <span class="name">流水号</span>
                                <span v-text="vipObj.code"></span>
                            </div>
                        </div>
                        <p class="selPayType flex flex-align-center">选择支付方式</p>
                        <div class="pay_type clearfix">
                            <!-- <input name="Fruit" type="radio" value="CASH" v-model="payVipType"> -->
                            <span class="left size1 dfgdfgdf" @click="changeVipPayType('CASH')" :class="{span_active:payVipType == 'CASH'}">现金支付</span>
                            <!-- <input name="Fruit" type="radio" value="PAYCARD" v-model="payVipType"> -->
                            <span v-if="isOnline" class="left size1" @click="openPayCodeBoxForVip('PAYCARD')" :class="{span_active:payVipType == 'PAYCARD'}">在线支付</span>

                            <span v-if="!isOnline" class="left size1" :class="{span_active:payVipType == 'ALIPAY_CASH'}"><input name="Fruit" type="radio" value="ALIPAY_CASH" v-model="payVipType">支付宝支付</span>
                            <span v-if="!isOnline" class="left size1" :class="{span_active:payVipType == 'WECHATPAY_CASH'}"><input name="Fruit" type="radio" value="WECHATPAY_CASH" v-model="payVipType">微信支付</span>
                        </div>
                        <div class="sure_pay">
                            <button @click="vipPayFn" type="button">确认支付</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="vipCouponMask" v-if="showSelCoupon" @click="showSelCoupon=false">
            <div class="vipCouponBox" @click.stop="">
                <div class="title">会员优惠券</div>
                <div class="vipMsg clearfix">
                    <div class="name left">会员名称：</div>
                    <div class="val left" v-text="curSelectVipData.name"></div>
                    <div class="name left">会员帐号：</div>
                    <div class="val left" v-text="curSelectVipData.mobile?curSelectVipData.mobile:curSelectVipData.code"></div>
                </div>
                <div class="selCouponBox">
                    <div class="coupon-scroll-box">
                        <div class="item" v-for="(item,idx) in couponList" @click.stop="selCouponItem(item,idx)" :key="idx" :class="{active:idx==curCouponIdx}">
                            <el-dropdown @command="handleCommand" trigger="click">
                                <div>
                                    <span class="coupon_title" v-text="item.title"></span>
                                    <div class="left typeAddProduct">
                                        <span class="typeName" v-text="couponType[item.type]"></span>
                                        <span>-</span>
                                        <span v-text="item.productName"></span>
                                    </div>
                                    <div class="deadLine">
                                        <span>有效日期：</span>
                                        <span>{{item.beginTime | numberToAllDate('')}}</span>
                                        <span>~</span>
                                        <span>{{item.endTime | numberToAllDate('')}}</span>
                                    </div>
                                </div>
                                <el-dropdown-menu slot="dropdown" v-if="item.products && item.products.length>1">
                                <!-- <el-dropdown-menu slot="dropdown" v-if="item.products"> -->
                                    <el-dropdown-item :command="it" v-for="(it,ind) in item.products" :key="ind">{{it.productName}}</el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown>
                            <!-- <div class="deadLine">
                                <span>有效日期：</span>
                                <span>{{item.beginTime | numberToAllDate('')}}</span>
                                <span>~</span>
                                <span>{{item.endTime | numberToAllDate('')}}</span>
                            </div> -->
                        </div>
                    </div>
                    <div class="btnGroup" style="color:red;" v-if="nowSelCouponItem&&nowSelCouponItem.productName">
                        <span>*当前选择的优惠券抵扣商品是：{{nowSelCouponItem.productName}}</span>
                    </div>
                    <div class="btnGroup">
                        <button type="button" class="cancel" @click="showSelCoupon=false">取消</button>
                        <button type="button" class="save" @click="choiceCoupon()">确认</button>
                    </div>
                </div>
            </div>
        </div>
        <div style="display:none;">
            <div id="receipt">
                <div style="width: 164px; fontSize: 12px;">
                    <h1 style="text-align:center;font-size:18px;"  v-text="'欢迎光临'+storeName">欢迎使用火星捕手</h1>
                    <p style="text-align:center;font-size:16px;" v-text="'销售单据'"></p>
                    <div>
                        <span>座位号:</span>
                        <span style="font-size:18px;" v-text="printData.tableNo"></span>
                    </div>
                    <div>
                        <span>打印时间:</span>
                        <span>{{new Date() | numberToAllDate('')}}</span>
                    </div>
                    <div>
                        <span>流水号:</span>
                        <span>{{code}}</span>
                    </div>
                    <div style="margin-bottom: 10px;">
                        <span>创建人:</span>
                        <span>{{storeInfo.employeeName}}</span>
                    </div>
                    <div v-for="(item,idx) in printData.goodArr" v-if="item.productName">
                        <div>
                            <span>名称：</span>
                            <span v-text="item.productName"></span>
                        </div>
                        <div style="width:35%;display:inline-block">
                            <span>数量：</span>
                            <span v-text="item.quantity"></span>
                        </div>
                        <div style="width:60%;display:inline-block">
                            <span>单价：</span>
                            <span v-text="(item.salesPrice/item.quantity).toFixed(2)"></span>
                        </div>
                        <div style="line-height:3px;">----------------------------------</div>
                    </div>
                    <div style="margin-top: 10px;">
                        <span>合计：</span>
                        <span v-text="printData.total.toFixed(2)"></span>
                    </div>
                    <div>
                        <span>总数：</span>
                        <span v-text="printData.count"></span>
                    </div>
                    <div>
                        <span>优惠：</span>
                        <span v-text="printData.discount.toFixed(2)"></span>
                    </div>
                    <div>
                        <span>应付：</span>
                        <span v-text="printData.amount.toFixed(2)"></span>
                    </div>
                    <div>
                        <span>备注：</span>
                        <span v-text="printData.notes"></span>
                    </div>
                </div>
            </div>
        </div>
        <div style="display:none;">
            <div id="paster">
                <div style="text-align:center">乐事薯片柠檬味</div>
                <div style="text-align:center">￥5.00</div>
            </div>
        </div>
        <div style="display: none" id="speech_voice" v-text="voice_text"></div>
        <div class="alert-pwd" v-if="showAlertPwd" @click="showAlertPwd=false">
            <div class="alert-pwd-wrap" @click.stop="">
                <div class="inner-wrap">
                    <span>折扣抹零前，请输入密码。</span>
                    <input type="password" name="" v-focus @keydown.enter="checkDiscountPwd" v-model="disCountPwd" placeholder="请输入密码" id="" />
                    <div>
                        <button @click="checkDiscountPwd">确定</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="multi-count-wrap" v-if="showMultiCount" @click.stop="showMultiCount=false;">
            <div class="int-count" @click.stop="">
                <input type="text" placeholder="请输入数量(添加或减少，如5)..." v-model="mutilCount" />
                <div class="btn">
                    <button @click="showMultiCount=false;">取消</button>
                    <button class="sure" @click="addProductForMutil(multiCountItem,mutilCount)">确定</button>
                </div>
            </div>
        </div>
        <!-- 配品 -->
        <el-dialog
            :close-on-click-modal="false"
            :title="nowSelNeedPeiItem?`请选择配品-${nowSelNeedPeiItem.productName}`:'--'"
            :visible.sync="showPeiGoods"
            :close-on-press-escape="false"
            width="500px"
            :show-close="false"
            >
            <div class="pei-wrap">
                <div class="pei-type" v-for="(item,index) in peiGoods" :key="index">
                    <!-- <div class="typename">{{item.typeName}}</div> -->
                    <div class="pei-item" :class="{active:nowSelPeiGoodsIds.indexOf(it.id)!=-1}" v-for="(it,ind) in item.list" :key="`_${ind}`" @click="modifyPeiGoods('add',it)">
                        <div class="item-name">{{it.name}}</div>
                        <div class="item-price">￥{{it.salesPrice}}</div>
                    </div>
                </div>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="cancelPei">跳 过</el-button>
                <el-button type="primary" @click="submitSelPei">选好了</el-button>
            </span>
        </el-dialog>
        <!-- 规格 -->
        <el-dialog
            :title="nowSelNeedSpecItem?`选择规格-${nowSelNeedSpecItem.name}`:'--'"
            :visible.sync="showSelSpec"
            :close-on-press-escape="false"
            :close-on-click-modal="false"
            :show-close="false"
            width="500px"
            >
            <div class="pei-wrap" v-for="(item,index) in specs" :key="index">
                <div class="spec-name">{{item.name}}</div>
                <div class="pei-item" :class="{active:(item.seledSpec&&item.seledSpec==it)}" v-for="(it,ind) in item.specs" :key="`_${ind}`" @click="modifySpecs('add',it,item)" >
                    <div class="item-name">{{it}}</div>
                </div>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="beforeCloseSpec">取 消</el-button>
                <el-button type="primary" @click="submitSelSpec">确 定</el-button>
            </span>
        </el-dialog>
        <!--  -->
        <el-dialog
            title="租赁商品"
            :visible.sync="showRentInfo"
            :close-on-press-escape="false"
            :close-on-click-modal="false"
			:before-close="handleClose"
            :show-close="true"
            width="450px"
            >
            
            <div class="rent-wrap">
				<div class="tit">押金合计</div>
                <div class="sel-item-wrap">
                <div class="sel-item">
                    <!-- <div class="item-name">选择机位</div> -->
                    <div class="sel-cont">
                        <div class="cont-item">
                            <span class="cont-name">区域:</span>
                            <el-select v-model="rentForm.areaId" @change="changeArea" size="mini" style="width:calc(100% - 50px)" placeholder="选择区域">
                                <el-option
                                v-for="item in areas"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                                </el-option>
                            </el-select>
                        </div>
                        <div class="cont-item">
                            <span class="cont-name">机位:</span>
                            <el-select v-model="rentForm.numId" @change="changeTable" size="mini" style="width:calc(100% - 50px)" placeholder="选择机位">
                                <el-option
                                v-for="item in tables"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
                <div class="sel-item">
                    <!-- <div class="item-name">计费规则</div> -->
                    <div class="sel-cont">
                        <div class="cont-item">
                            <span class="cont-name">规则:</span>
                            <el-select v-model="rentForm.ruleId" @change="changeRule" style="width:calc(100% - 50px)" size="mini" placeholder="选择规则">
                                <el-option
                                v-for="item in nowSelRentGoodsRules"
                                :key="item.ruleId"
                                :label="item.ruleName"
                                :value="item.ruleId">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
                <div class="sel-item">
                    <!-- <div class="item-name">顾客信息</div> -->
                    <div class="sel-cont">
                        <div class="cont-item">
                            <span class="cont-name">手机:</span>
                            <el-input size="mini" type="text" style="width:calc(100% - 50px)" v-model="rentForm.mobile" />
                        </div>
                    </div>
                </div>
            </div>
				<div class="rent-list">
					<div class="rent-head">
						<span class="it">商品</span>
						<span class="it">详情</span>
					</div>
					<div class="rent-goods">
						<div class="r-li">
							<span class="it" v-if="nowSelRentGoods">{{nowSelRentGoods.name}}</span>
							<span class="it">数量:1</span>
						</div>
						<div class="r-li">
							<span class="it">押金</span>
							<span class="it">{{nowSelRentRule ? Number(nowSelRentRule.amount).toFixed(2) : "--"}}</span>
						</div>
						<div class="r-li">
							<span class="it">租赁规则</span>
							<span class="it">{{nowSelRentRule ? nowSelRentRule.ruleName : "--"}}</span>
						</div>
					</div>
				</div>
				<div class="btns">
					<span class="btn submit" @click="sureSelRentInfo">支付押金</span>
				</div>
			</div>
        </el-dialog>
        <!--  -->
    </div>
</template>

<script type="text/javascript">
import API_BASE_URL,{BASE_URL} from "./../../urlConfig/index";
console.log(API_BASE_URL)
export default {
    props: ['routeSelectVipData','storeId', 'printsBtn', 'isOnline','storeName','endTime'],//storeId店铺id，orderId 订单id 是否走银行通道 isOnline
    data(){
        return{
            curOrderData:null,
            nowSelRentRule:null,
            showPayCodeBoxForRent:false,
            nowSelRentGoodsRules:[],
            nowSelRentGoods:null,
            rentForm:{
                name:"",
                mobile:"",
                empId:"",
                empName:"",
                ruleId:"",
                productId:"",
                areaId:"",
                numName:"",
                numId:"",
                source:"POS"
            },
            sourceType: {
				POS: "收银台",
				WEB: "电脑点单",
				EMPLOYEE: "店员宝",
				WEIXIN: "微信点单",
				CONSUMER: "消费者，微信",
				TAKEOUT: "三方外卖"
			},
            tables:[],
            areas:[],
            showRentInfo:false,
            leaseProductEnabled:false,
            rentCates:[],
            nowReduceItem:null,
            nowSelNeedSpecItem:null,
            nowSelSpec:[],
            specs:[],
            fromSelSpec:false,
            showSelSpec:false,
            // 
            nowSelCouponItem:{},
            peiGoods:[],
            showPeiGoods:false,
            allowProductCancelSale:true,
            notesArr:[],//备注数组
            selNotes:false,//是否支持选择备注
            chainEnabled:false,
            mutilCount:"",//自定义数量
            multiCountItem:{},
            showMultiCount:false,//显示批量输入框
            wipeZeroMoney:'',
            checkedWipeZero:false,
            showDiscount:false,
            showZero:false,
            disCountPwd:"",
            showAlertPwd:false,
            showSetWrap:false,//是否显示抹零设置窗口
            lastDiscount:0,
            firstDiscount:0,
            discountVals:[0,1,2,3,4,5,6,7,8,9],
            endDay:0,//到期天数
            showMenu:true,//是否显示菜单
            canClick:true,//用于处理快速点击
            storeInfo:{},//店铺信息
            inputVipMoney:"",//自定义充值金额
            vipObj:{},//会员充值信息
            vipPayBtn:false,//会员充值
            rulesData:[],//充值规则数组
            addVipBtn: false, // 控制会员添加弹出框
            showRechargeBox: false, // 显示会员充值框
            showSelCoupon: false, // 选择优惠券弹框
            vipNumber: '', // 会员帐号
            vipList: [], // 会员列表
            curVipIdx: 0, // 当前会员索引
            searchVipBtn: true, // 搜索会员接口控制
            curSelectVipData: '', // 会员数据

            choiceArr: [], // 选择商品列表
            curActiveBtn: 0,
            upBtn: false,  // 控制挂单弹出框样式
            payType : "", // 商品支付方式
            payVipType : "", // 会员支付方式

            newOrderStatus: { // 判断需要生成新订单的状态
                UNFINISHED:1,
                FINISHED:1,
                CANCELED:1,
                REFUNDED:1,
            },
            couponType: {
                'GET_ITEM_FREE': '商品抵用券'
            },

            goodsData:[ // 全部商品数据
                {
                    products:[],
                    subTypes:[
                        {
                            products:[]
                        }
                    ]
                }
            ], // 商品列表
            curSelectGoodsData: [], // 当前选中的商品数据
            curIdx:0, // 当前选择商品分类索引
            curSmallTypeIdx: -1, // 当前选择细类索引
            totalPrice: { // 选择商品总计
                count: 0, // 总数量
                total: 0, // 总计金额
                discount: 0, // 优惠金额
                amount: 0, // 最终价格
                removeZero:0
            },
            orderId: this.ordersId, // 订单id
            paymentBtn: true, // 支付控制，true:可以支付
            goodSearch: '', // 商品搜索
            curGoodIdx: 0, // 当前商品索引
            goodList: [], // 模糊检索商品列表
            code:'',//流水号

            addGoodBtn: true, // 控制添加商品
            reduceGoodBtn: true, // 控制减少商品

            pageSize: 5, // 默认选择商品数量
            productStatus: {//商品上下架
                status:'',
                id:'',
                btn:false,
                name:''
            },
            showConfirmMask: false, // 删除订单确认
            showOnLinePaySuccessMask: false, // 在线支付成功
            localPrintsBtn: this.printsBtn,//是否单据打印
            printsNum:1,//单据打印的份数
            notes:'',//备注
            tableNo:'',//座位号
            payApiBtn: true, // 支付情况控制

            payCode: '', // 用户支付授权码
            showPayCodeBox: false, // 是否显示在线支付
            showPayLoding: false, // 是否显示等待支付框

            printData: { //打印数据
                goodArr: [],
                count: 0, // 总数量
                total: 0, // 总计金额
                discount: 0, // 优惠金额
                amount: 0, // 最终价格
                tableNo: '', // 座位号
                notes: '', // 备注
                createTime:0
            },
            isCostPrintBtn:false,//是否打印网费

            couponList: [], // 优惠券列表
            curBindCoupon: [], // 当前已经绑定了的优惠券列表
            curCouponData: {}, // 当前选择优惠券
            curCouponIdx: 0, // 当前选中优惠券索引

            curCouponPage: 0, // 优惠券页码
            couponPageSize: 1000, // 优惠券每页条数

            timeNum: true, // 支付等待时间
            payLoadTimer:'',//支付时间控制器
            showCustomPrice: false, // 显示自定义充值框
            customPrice: '', // 自定义价格

            voice_text: '', // 文字转语音

            canDeletepayment: false, // 是否能取消支付
            delPaymentLodingTime: 30, // 取消支付等待时间
            delPaymentApiBtn: true, //
            curSelCouponId:[],
            channelType: { // 结算方式
				// ALIPAY: '支付宝',
				// CASH: '现金',
				// WECHATPAY: '微信',
				// MEMBER : '会员支付',
				// WECHATPAY_CASH : '线下微信',
				// ALIPAY_CASH : '线下支付宝',
				"CASH": "现金",
				"ALIPAY": "支付宝",
				"WECHATPAY": "微信",
				"UNIONPAY": "银联",
                "pay.weixin.micropay":"微信刷卡",
                "pay.wechat.micropay":"微信刷卡",
				"pay.alipay.micropay":"支付宝刷卡",
				"pay.jdpay.micropay":"京东刷卡",
				"pay.qq.micropay":"QQ钱包刷卡",
				"pay.shiming.micropay":"会员卡",
				"pay.unionpay.micropay":"银联支付",
				"pay.bestpay.micropay":"翼支付",
                "pay.weixin.native":"微信扫码",
                "pay.wechat.native":"微信扫码",
				"pay.alipay.native":"支付宝扫码",
				"ALIPAY_CASH":"支付宝线下",
				"WECHATPAY_CASH":"微信线下",
				"COUPON":"优惠券",
				"MEMBER":"会员",
                "pay.wechat.jspay":"微信网页支付",
                "pay.alipay.jspay":"支付宝网页支付",
			},
            nowSelPeiGoods:[],
            nowSelNeedPeiItem:null,
            nowSelPeiGoodsIds:[],
        }
    },
    watch:{
        selNotes(val){
            localStorage.setItem("selNotes",JSON.stringify(val));
            if(!val){
                this.notes = "";
            }else{
                if(this.notesArr.length){
                    this.notes = this.notesArr[0].message;
                }
            }
        },
        showMultiCount(val){
            if(!val){
                this.mutilCount = "";
            }
        },
        //搜索获取会员
        vipNumber (val) {
            if ( !this.searchVipBtn || !val ) {
                return;
            }
            this.searchVipBtn = false;
            this.$http.get('members?storeId='+this.storeId+'&q='+val).then((res) => {
                this.vipList = res.data;
                this.searchVipBtn = true;
                setTimeout(()=>{
                    let that = this;
                    $('.vipCheckList li').hover( function () {
                        that.curVipIdx = $(this).index()-1;
                    }, function () {
                        that.curVipIdx = 0;
                    })
                },0)
            }).catch(()=>{
                this.searchVipBtn = true;
            })
        },
        printsBtn ( val ) {
            this.localPrintsBtn = val;
        },
       //搜索获取商品
        goodSearch ( val ) {
            if ( !(val.replace(/\s/g,'')) ) {
                this.goodList = [];
                return;
            }
            this.$http.get('products/search?storeId='+this.storeId+'&q='+encodeURI(val)).then((res)=>{
                this.goodList = res.data;
                setTimeout(()=>{
                    let that = this;
                    $('.goodCheckList li').hover( function () {
                        that.curGoodIdx = $(this).index()-1;
                    }, function () {
                        that.curGoodIdx = 0;
                    })
                },0)
            })
        },
        showPeiGoods(val){
            if(!val){
                this.nowSelPeiGoods = [];
                this.nowSelPeiGoodsIds = [];
                this.nowSelNeedPeiItem = null;
            }
        }
    },
    methods:{
        handleClose(){
			this.cancelRentInfo();
		},
        beforeCloseSpec(){
            // if(!this.nowSelSpec || !this.nowSelSpec.length){
            //     this.$message({
            //         message: "请选择规格",
            //         showClose: true,
            //         type: 'error'
            //     });
            //     return;
            // }
            this.nowSelNeedSpecItem = null;
            this.nowSelSpec = [];
            this.fromSelSpec = false;
            this.showSelSpec = false;
        },
        modifySpecs(type,it,item){
            item.seledSpec = it;
            console.log(this.specs);
            let nowSelSpec = [];
            if(this.specs && Array.isArray(this.specs) && this.specs.length){
                this.specs.forEach(it=>{
                    if(it.seledSpec){
                        nowSelSpec.push(it.seledSpec);
                    }
                })
            }
            // let nowSelSpec = JSON.parse(JSON.stringify(this.nowSelSpec));
            // if(type == "add"){
            //     if(nowSelSpec.indexOf(item)!=-1){
            //         nowSelSpec.splice(nowSelSpec.indexOf(item),1);
            //     }else{
            //         nowSelSpec.push(item);
            //     }
            // }
            console.log(nowSelSpec)
            this.nowSelSpec = nowSelSpec;
        },
        submitSelSpec(){
            if(!this.nowSelSpec || !this.nowSelSpec.length ){
                this.$message({
                    message: "请选择规格",
                    showClose: true,
                    type: 'error'
                });
                return;
            }
            console.log(this.nowSelSpec);
            if(this.nowSelSpec.length!=this.specs.length){
                this.$message({
                    message: "请完整选择规格",
                    showClose: true,
                    type: 'error'
                });
                return;
            }
            // 
            this.goodSearch = '';
            if ( this.upBtn ) return;
            if ( this.nowSelNeedSpecItem.id == '0' ) {
                this.showCustomPrice = true;
                this.customPrice = '';
                setTimeout(()=>{
                    $('#customPriceInput').focus();
                })
                return;
            }
            this.fromSelSpec = true;
            this.addProduct( this.nowSelNeedSpecItem.id );
            this.canClick = false;
            setTimeout(()=>{
                this.canClick = true;
            },500);
            // 
        },
        // 
        reduceAmountForPei(it){
            if(!this.canClick){
                return;
            }
            this.canClick = false;
            this.$http({
                url:`orders/${this.orderId}/remove/match`,
                method:"POST",
                data:{
                    orderItemId:it.id,
                    productCount:1
                }
            }).then(res=>{
                this.$message({
                    message: "操作成功",
                    showClose: true,
                    type: 'success'
                });
                // 
                let body = res.data;
                let items = body.items;
                let discountOrderItem = res.data.discountOrderItem;
                for(let i=0;i<items.length;i++){
                    items[i].isDiscountForSecond = false;
                    for(let j=0;j<discountOrderItem.length;j++){
                        if(items[i].productId == discountOrderItem[j].productId){
                            items[i].discountForSecondQty = discountOrderItem[j].qty;
                            items[i].isDiscountForSecond = true;
                        }
                    }
                }
                console.log(items)
                this.choiceArr = items;
                this.totalPrice = {
                    count:    body.count, // 总数量
                    total:    body.total, // 总计金额
                    discount: body.discount, // 优惠金额
                    amount:   body.amount, // 最终价格
                    removeZero:   body.removeZero, // 最终价格
                }
                for (let i = 0, len = this.pageSize - this.choiceArr.length; i < len; i++) {
                    this.choiceArr.push({});
                }
                this.addGoodBtn = true;
                // 
                setTimeout(()=>{
                    this.canClick = true;
                },1000);
                // this.shopUpBoxForReturnMoney(false);
                return;
            }).catch(err=>{
                setTimeout(()=>{
                    this.canClick = true;
                },1000);
            })
        },
        addAmountForPei(item,it){
            if(!this.canClick){
                return;
            }
            this.canClick = false;
            let data = {
                    orderItemId:item.id,
                    orderId:this.orderId,
                    matchParams:[
                        {
                            masterItemId:it.id,
                            productId:it.productId,
                            productCount:1,
                            amount:(it.salesPrice / it.quantity).toFixed(2),
                        }
                    ]
                }
                this.$http({
                    url:`orders/${this.orderId}/add/match`,
                    method:"POST",
                    data
                }).then(res=>{
                    this.showPeiGoods = false;
                    this.$message({
                        message: "操作成功",
                        showClose: true,
                        type: 'success'
                    });
                    // 
                    let body = res.data;
                    let items = body.items;
                    let discountOrderItem = res.data.discountOrderItem;
                    for(let i=0;i<items.length;i++){
                        items[i].isDiscountForSecond = false;
                        for(let j=0;j<discountOrderItem.length;j++){
                            if(items[i].productId == discountOrderItem[j].productId){
                                items[i].discountForSecondQty = discountOrderItem[j].qty;
                                items[i].isDiscountForSecond = true;
                            }
                        }
                    }
                    console.log(items)
                    this.choiceArr = items;
                    this.totalPrice = {
                        count:    body.count, // 总数量
                        total:    body.total, // 总计金额
                        discount: body.discount, // 优惠金额
                        amount:   body.amount, // 最终价格
                        removeZero:   body.removeZero, // 最终价格
                    }
                    for (let i = 0, len = this.pageSize - this.choiceArr.length; i < len; i++) {
                        this.choiceArr.push({});
                    }
                    this.addGoodBtn = true;
                    // 
                    setTimeout(()=>{
                        this.canClick = true;
                    },1000);
                    // this.shopUpBoxForReturnMoney(false);
                }).catch(err=>{
                    setTimeout(()=>{
                        this.canClick = true;
                    },1000);
                })
        },
        modifyPeiGoods(type,item){
        //    if(this.nowSelPeiGoods!=null && item.productId != this.nowSelPeiGoods.productId){
        //        this.$message({
        //             message: "暂支持添加单个配品",
        //             showClose: true,
        //             type: 'error'
        //         });
        //        return;
        //    }
            // if(type == "add"){
            //     item.selCount++;
            //     this.nowSelPeiGoods = item;
            // }else{
            //     item.selCount--;
            //     if(item.selCount <= 0){
            //         item.selCount = 0;
            //         this.nowSelPeiGoods = null;
            //         return;
            //     }
            // }
            if(type == "add"){
                let nowSelPeiGoods = JSON.parse(JSON.stringify(this.nowSelPeiGoods));
               
                let flag = true;
                let index;

                // if(this.nowSelNeedPeiItem.openMatchEnabled){
                //     let typeObj = {};
                //     this.peiGoods.forEach(it=>{
                //         typeObj[it.typeId] = false;
                //     })
                //     if(nowSelPeiGoods && Array.isArray(nowSelPeiGoods) && nowSelPeiGoods.length){
                //         for(let k in typeObj){
                //             nowSelPeiGoods.forEach((it,ind)=>{
                //                 if(it.productType.id == k){
                //                     typeObj[k] = true;
                //                 }
                //             })
                //         }
                //         nowSelPeiGoods.forEach((it,ind)=>{
                //             if(it.id == item.id){
                //                 flag = false;
                //                 index = ind;
                //             }
                //         })
                //     }
                //     // 
                //     let specFlag = false;
                //     for(let k in typeObj){
                //         if(!typeObj[k]){
                //             specFlag = true;
                //         }
                //     }
                //     if(specFlag){
                //         this.$message({
                //             message: "请选择规格",
                //             showClose: true,
                //             type: 'error'
                //         });
                //     }
                //     // 
                //     return;
                // }
                // 
                if(nowSelPeiGoods && Array.isArray(nowSelPeiGoods) && nowSelPeiGoods.length){
                    nowSelPeiGoods.forEach((it,ind)=>{
                        if(it.id == item.id){
                            flag = false;
                            index = ind;
                        }
                    })
                }
                if(flag){
                    let canPushIndex = -1;
                    if(this.nowSelNeedPeiItem.openMatchEnabled){
                        nowSelPeiGoods.forEach((it,ind)=>{
                            if(it.productType.id == item.productType.id){
                                canPushIndex = ind;
                            }
                        })
                    }
                    if(canPushIndex!=-1){
                        nowSelPeiGoods.splice(canPushIndex,1,item);
                    }else{
                        nowSelPeiGoods.push(item);
                    }
                }else{
                    if(this.nowSelNeedPeiItem.openMatchEnabled){
                        return;
                    }
                    nowSelPeiGoods.splice(index,1);
                }

                let nowSelPeiGoodsIds = [];
                nowSelPeiGoods.forEach(it=>{
                    nowSelPeiGoodsIds.push(it.id);
                });
                this.nowSelPeiGoods = nowSelPeiGoods;
                this.nowSelPeiGoodsIds = nowSelPeiGoodsIds;
            }
        },
        submitSelPei(){
            if(this.peiGoods && Array.isArray(this.peiGoods) && this.peiGoods.length){
                if(!this.canClick){
                    return;
                }
                this.canClick = false;
                let matchParams = [];
                if(this.nowSelPeiGoods && Array.isArray(this.nowSelPeiGoods) && this.nowSelPeiGoods.length){
                    this.nowSelPeiGoods.forEach(it=>{
                        let obj = {
                            masterItemId:"",
                            productId:it.id,
                            productCount:1,
                            amount:it.salesPrice,
                        }
                        matchParams.push(obj);
                    })
                }
                if(!matchParams.length){
                    this.$message({
                        message: "请选择规格",
                        showClose: true,
                        type: 'error'
                    });
                    this.canClick = true;
                    return;
                }
                let data = {
                    orderItemId:this.nowSelNeedPeiItem.id,
                    orderId:this.orderId,
                    matchParams
                    // masterItemId:"",
                    // productId:this.nowSelPeiGoods.id,
                    // productCount:this.nowSelPeiGoods.selCount,
                    // amount:Number(this.nowSelPeiGoods.selCount)*Number(this.nowSelPeiGoods.salesPrice),
                }
                this.$http({
                    url:`orders/${this.orderId}/add/match`,
                    method:"POST",
                    data
                }).then(res=>{
                    this.showPeiGoods = false;
                    this.$message({
                        message: "操作成功",
                        showClose: true,
                        type: 'success'
                    });
                    let body = res.data;
                    let items = body.items;
                    let discountOrderItem = res.data.discountOrderItem;
                    for(let i=0;i<items.length;i++){
                        items[i].isDiscountForSecond = false;
                        for(let j=0;j<discountOrderItem.length;j++){
                            if(items[i].productId == discountOrderItem[j].productId){
                                items[i].discountForSecondQty = discountOrderItem[j].qty;
                                items[i].isDiscountForSecond = true;
                            }
                        }
                    }
                    console.log(items)
                    this.choiceArr = items;
                    this.totalPrice = {
                        count:    body.count, // 总数量
                        total:    body.total, // 总计金额
                        discount: body.discount, // 优惠金额
                        amount:   body.amount, // 最终价格
                        removeZero:   body.removeZero, // 最终价格
                    }
                    for (let i = 0, len = this.pageSize - this.choiceArr.length; i < len; i++) {
                        this.choiceArr.push({});
                    }
                    this.addGoodBtn = true;
                    setTimeout(()=>{
                        this.canClick = true;
                    },1000);
                    // this.shopUpBoxForReturnMoney(false);
                }).catch(err=>{
                    setTimeout(()=>{
                        this.canClick = true;
                    },1000);
                })
            }
        },
        cancelPei(){
            if(this.nowSelNeedPeiItem.openMatchEnabled || (this.choiceItem&&this.choiceItem.openMatchEnabled)){
                if(!this.nowSelPeiGoods || !Array.isArray(this.nowSelPeiGoods) || !this.nowSelPeiGoods.length){
                    this.$message({
                        message: "请选择相应规格",
                        showClose: true,
                        type: 'error'
                    });
                    return false;
                }else{
                    if(!this.nowSelNeedPeiItem.masterItemDtos || !Array.isArray(this.nowSelNeedPeiItem.masterItemDtos)||!this.nowSelNeedPeiItem.masterItemDtos.length){
                        this.$message({
                            message: "请选择相应规格",
                            showClose: true,
                            type: 'error'
                        });
                        return false;
                    }
                    this.showPeiGoods = false
                }
            }else{
                this.showPeiGoods = false
            }
        },
        doShowPeiGoods(item){
            this.nowSelNeedPeiItem = item;
            this.nowSelPeiGoodsIds = [];
            this.nowSelPeiGoods = [];
            if(item.masterItemDtos && Array.isArray(item.masterItemDtos) && item.masterItemDtos.length){
                let nowSelPeiGoodsIds = [];
                let masterItemDtos = JSON.parse(JSON.stringify(item.masterItemDtos));
                let obj = {};
                masterItemDtos.forEach(it=>{
                    obj[it.productId] = it;
                    nowSelPeiGoodsIds.push(it.productId);
                });
                let tempArr = [];
                for(let k in obj){
                    obj[k]["id"] =  obj[k].productId;
                    tempArr.push(obj[k]);
                }
                this.nowSelPeiGoodsIds = nowSelPeiGoodsIds;
                this.nowSelPeiGoods = tempArr;
            }
            this.$http({
                url:"match/product/list",
                method:"POST",
                data:{
                    productId:item.productId
                }
            }).then(res=>{
                let typeObj = {};
                if(res.data && Array.isArray(res.data) && res.data.length){
                    res.data.forEach(it=>{
                        typeObj[it.productType.id] = [];
                        it.selCount = 0;
                    })
                    for(let k in typeObj){
                      res.data.forEach(it=>{
                        if(it.productType.id==k){
                            typeObj[k].push(it);
                        } 
                      })  
                    }
                    let tempArr = [];
                    for(let k in typeObj){
                        tempArr.push({
                            typeName:typeObj[k][0].productType.name,
                            typeId:typeObj[k][0].productType.id,
                            list:typeObj[k]
                        })
                    }
                    this.peiGoods = tempArr;
                    // 
                    if(item.openMatchEnabled){
                        let nowSelPeiGoodsIds = [];
                        let nowSelPeiGoods = [];
                        tempArr.forEach(it=>{
                            if(it.list && Array.isArray(it.list) && it.list.length){
                                nowSelPeiGoods.push(it.list[0]);
                            }
                        })
                        nowSelPeiGoods.forEach(it=>{
                            nowSelPeiGoodsIds.push(it.id);
                        });
                        this.nowSelPeiGoods = nowSelPeiGoods;
                        this.nowSelPeiGoodsIds = nowSelPeiGoodsIds;
                    }
                    // 
                    this.showPeiGoods = true;
                }else{
                   this.$message({
                        message: "暂无相关配品，请在后台设置。",
                        showClose: true,
                        type: 'error'
                    });
                    return;
                }
            })
        },
        // 
        doShowMultiCount(item){
            this.showMultiCount = true;
            this.multiCountItem = item;
        },
        wipeZero(){
            if(!sessionStorage.getItem("ordersId")){
                this.$message({
                    message: "暂无订单",
                    showClose: true,
                    type: 'error'
                });
                return;
            }
            // let amount = Math.floor(this.totalPrice.amount.toFixed(2));
            if(Number(this.wipeZeroMoney) > this.totalPrice.amount.toFixed(2)){
                this.wipeZeroMoney = this.totalPrice.amount.toFixed(2);
            }
            let amount = this.wipeZeroMoney;
            console.log(amount);
            this.$http({
                url:"remove-zero",
                method:"POST",
                data:{
                    orderId:this.orderId,
                    amount
                }
            }).then(res=>{
                if(res.data.result.code == 400){
                    this.$message({
                        message: res.data.result.msg,
                        showClose: true,
                        type: 'error'
                    });
                    return; 
                }else if(res.data.result.code == 200){
                    this.$message({
                        message: res.data.result.msg,
                        showClose: true,
                        type: 'success'
                    });
                    this.showSetWrap = false;
                    this.showAlertPwd = false;
                    this.disCountPwd = "";

                    let body = res.data.data;

                    let items = body.items;
                    let discountOrderItem = res.data.discountOrderItem;
                            
                    for(let i=0;i<items.length;i++){
                        items[i].isDiscountForSecond = false;
                        for(let j=0;j<discountOrderItem.length;j++){
                            if(items[i].productId == discountOrderItem[j].productId){
                                items[i].discountForSecondQty = discountOrderItem[j].qty;
                                items[i].isDiscountForSecond = true;
                            }
                        }
                    }

                    this.choiceArr = items;

                    this.totalPrice = {
                        count:    body.count, // 总数量
                        total:    body.total, // 总计金额
                        discount: body.discount, // 优惠金额
                        amount:   body.amount, // 最终价格
                        removeZero:   body.removeZero, // 最终价格
                    }
                    this.checkedWipeZero = false;
                }
            })
        },
        showPwd(){
            if(this.showSetWrap){
                return;
            }
            this.showAlertPwd=true;
        },
        checkDiscountPwd(){
            if(!this.disCountPwd){
               this.$message({
                    message: "请输入密码",
                    showClose: true,
                    type: 'error'
                });
                return; 
            }
            let pwd = new Base64();
            let pwdStr = 'hxbs 123.999'+ pwd.encode(this.disCountPwd);
            this.$http({
                url:"judge-psw",
                method:"POST",
                data:{
                    storeId:this.storeId,
                    judgePsw:pwdStr
                }
            }).then(res=>{
                if(res.data.code == 400){
                    this.$message({
                        message: res.data.msg,
                        showClose: true,
                        type: 'error'
                    });
                    return; 
                }else if(res.data.code == 200){
                    this.showSetWrap = true;
                    this.showAlertPwd = false;
                    this.disCountPwd = "";
                }
            })
        },
        //打折
        discountThisOrder(){
            if(!sessionStorage.getItem("ordersId")){
                this.$message({
                    message: "暂无订单",
                    showClose: true,
                    type: 'error'
                });
                return;
            }

            this.$http({
                url:"return-order",
                method:"POST",
                data:{
                    orderId:this.orderId
                }
            }).then(res=>{
                console.log(res);
                if(res.data.result.code == 200){
                    let body = res.data.data;
                    this.choiceArr = body.items;
                    this.totalPrice = {
                        count:    body.count, // 总数量
                        total:    body.total, // 总计金额
                        discount: body.discount, // 优惠金额
                        amount:   body.amount, // 最终价格
                        removeZero:   body.removeZero, // 最终价格
                    }
                    let discountOrderItem = body.discountOrderItem;
                
                    // 
                    
                    if(this.firstDiscount == 0 && this.lastDiscount == 0){
                        if(this.wipeZeroMoney != ''){
                            if(!/^(0|[1-9][0-9]{0,9})(\.[0-9]{1,2})?$/.test(this.wipeZeroMoney)){
                                this.$message({
                                    message: "输入错误",
                                    showClose: true,
                                    type: 'error'
                                });
                                return;
                            }
                            this.wipeZero();
                        }
                        this.showSetWrap = false;
                        return; 
                    }
                    this.orderId = sessionStorage.getItem('ordersId');
                    let percent = parseFloat((`${this.firstDiscount}${this.lastDiscount}`)/100);
                    this.$http({
                        url:"discount",
                        method:"POST",
                        data:{
                            orderId:this.orderId,
                            percent
                        }
                    }).then(res=>{
                        if(res.data.result.code == 400){
                            this.$message({
                                message: res.data.result.msg,
                                showClose: true,
                                type: 'error'
                            });
                            return; 
                        }else if(res.data.result.code == 200){
                            this.$message({
                                message: res.data.result.msg,
                                showClose: true,
                                type: 'success'
                            });
                            this.showSetWrap = false;
                            this.showAlertPwd = false;
                            this.disCountPwd = "";

                            let body = res.data.data;

                            let items = body.items;
                            let discountOrderItem = res.data.discountOrderItem;

                            for(let i=0;i<items.length;i++){
                                items[i].isDiscountForSecond = false;
                                for(let j=0;j<discountOrderItem.length;j++){
                                    if(items[i].id == discountOrderItem[j].orderItem.id){
                                        items[i].discountForSecondQty = discountOrderItem[j].qty;
                                        items[i].isDiscountForSecond = true;
                                    }
                                }
                            }

                            this.choiceArr = items;

                            this.totalPrice = {
                                count:    body.count, // 总数量
                                total:    body.total, // 总计金额
                                discount: body.discount, // 优惠金额
                                amount:   body.amount, // 最终价格
                                removeZero:   body.removeZero, // 最终价格
                            }
                            // if(this.checkedWipeZero){
                            //     this.wipeZero();
                            // }
                            if(this.wipeZeroMoney != ''){
                                if(!/^(0|[1-9][0-9]{0,9})(\.[0-9]{1,2})?$/.test(this.wipeZeroMoney)){
                                    this.$message({
                                        message: "输入错误",
                                        showClose: true,
                                        type: 'error'
                                    });
                                    return;
                                }
                                this.wipeZero();
                            }
                        }
                    })
                    // 
                }else if(res.data.result.code == 400){
                    this.clearOrder();
                }
            });

        },
        upThisVip(){
            let vipDataId = (this.curSelectVipData&&this.curSelectVipData.id)?this.curSelectVipData.id:'';
            this.$http({
                url:"upgrade",
                method:"POST",
                data:{
                    storeId:this.storeId,
                    memberId:vipDataId
                }
            }).then(res=>{
                if(res.data.code == 200){
                    this.$message({
                        message: res.data.msg,
                        showClose: true,
                        type: 'success'
                    });
                }else if(res.data.code == 400){
                   this.$message({
                        message: res.data.msg,
                        showClose: true,
                        type: 'error'
                    }); 
                }
            });
        },
        doShowSupply(info){
            let date = new Date();
            let nowH = date.getHours();
            let nowM = date.getMinutes();

            console.log('当前时间为:'+nowH+' 分钟数wei:'+nowM);
            let notSupply = true;
            if(info!=='[]'&&info!==null){
                let timeData = JSON.parse(info);
                for(let i=0;i<timeData.length;i++){
                    if(nowH>=timeData[i].beginHour&&nowH<=timeData[i].endHour){
						if(nowH==timeData[i].beginHour&&nowM<timeData[i].beginMinute){
                            notSupply = true;
                            return notSupply;           
                        }
                        if(nowH==timeData[i].endHour&&nowM>timeData[i].endMinute){
                            notSupply = true;
                            return notSupply;           
                        }
                        notSupply = false;
                        return notSupply;
                    }
                }
                return notSupply;
            }else{
                return false;
            }
        },
        changePayType(str){
            this.payType = str;
            console.log("当前支付方式："+this.payType)
        },
        changeVipPayType(vipStr){
            this.payVipType = vipStr;
            console.log("vip支付方式为："+this.payVipType)
        },
        //获取即将切换的商品状态
        showpProductStatus(item){
            if(!this.allowProductCancelSale){
                this.$message({
                    message: "下架开关未开",
                    showClose: true,
                    type: 'error'
                });
                return;
            }
            // 
            this.productStatus.id=item.id;
            this.productStatus.name=item.name;
            this.productStatus.status=item.productStatus;
            this.productStatus.btn=true;
        },
        //切换商品状态
        sureProductStatus(){
            this.$http.post(this.productStatus.id+'/products-status?status='+(this.productStatus.status=="ON"?'OFF':'ON')).then((res)=>{
                this.productStatus = {
                    id:'',
                    name:'',
                    status:'',
                    btn:false
                }
                this.getGoods();
                this.$message({
                    message: '修改成功',
                    showClose: true,
                    type: 'success'
                });
            })
        },
        // 清除当前会员信息。回到选择会员
        closeVipFn(){
            this.vipPayBtn = false;
            this.showRechargeBox = false;
            let orderId = sessionStorage.getItem('ordersId');
            if(!orderId){
                this.curSelectVipData = '';
            }
            // this.curSelectVipData = '';
        },
         // 选择商品分类
        selGoodType: function (index) {
            $("#searchInput").focus();
            if ( this.curIdx !== index ) {
                $($('.goods_type_nav .nav_text')[index]).css('height', 'auto');
            } else {
                if ( $($('.goods_type_nav .nav_text')[index]).css('height') == '50px' ) {
                    $($('.goods_type_nav .nav_text')[index]).css('height', 'auto');
                } else {
                    $($('.goods_type_nav .nav_text')[index]).css('height', '50px');
                }
            }
            this.curIdx = index;
            this.curSmallTypeIdx = -1;
            this.curSelectGoodsData = this.goodsData[this.curIdx];
            this.vipPayBtn = false;
            this.showRechargeBox = false;
        },
        // 解除会员绑定
        deBindVip: function () {
            console.log(this.curSelectVipData)
            if(this.curBindCoupon && Array.isArray(this.curBindCoupon) && this.curBindCoupon.length){
                let productId = this.curBindCoupon[0].productId;
                
                this.$http.put('orders/'+this.orderId+'/relieveCouponInstance?couponInstanceCode='+this.curBindCoupon[0].couponInstanceCode+"&productId="+productId).then((res)=>{
                this.curBindCoupon = res.data.couponInstances;
                let body = res.data;
                let items = body.items;
                let discountOrderItem = res.data.discountOrderItem;
                        
                for(let i=0;i<items.length;i++){
                    items[i].isDiscountForSecond = false;
                    for(let j=0;j<discountOrderItem.length;j++){
                        if(items[i].id == discountOrderItem[j].orderItem.id){
                            items[i].discountForSecondQty = discountOrderItem[j].qty;
                            items[i].isDiscountForSecond = true;
                        }
                    }
                }

                this.choiceArr = items;
                this.totalPrice = {
                    count:    res.data.count, // 总数量
                    total:    res.data.total, // 总计金额
                    discount: res.data.discount, // 优惠金额
                    amount:   res.data.amount, // 最终价格
                    removeZero:   res.data.removeZero, // 最终价格
                }
                console.log(item);
                let index;
                for(let i=0;i<this.curSelCouponId.length;i++){
                    let couponCode = this.curSelCouponId[i].couponInstanceCode;
                    if(couponCode === item.couponInstanceCode){
                        index = i;
                    }
                }
                if(index > -1){
                    this.curSelCouponId.splice(index,1);
                }
                console.log(index)
                
                console.log(this.curSelCouponId);
                // 
                if( sessionStorage.getItem('ordersId') ) {
                    this.orderId = sessionStorage.getItem('ordersId');
                    let vipDataId = (this.curSelectVipData&&this.curSelectVipData.id)?this.curSelectVipData.id:'';
                    this.$http.put('orders/'+this.orderId+'/relieveMember?memberId='+vipDataId).then((res)=>{
                        this.curSelectVipData = '';
                        this.$http.get('orders/'+this.orderId).then((ress)=>{
                            if(!ress.data.id){
                                sessionStorage.removeItem("ordersId");
                                this.clearOrder();
                                return;
                            }
                            let resBody = ress.data;

                            let items = resBody.items;
                            let discountOrderItem = ress.data.discountOrderItem;
                                    
                            for(let i=0;i<items.length;i++){
                                items[i].isDiscountForSecond = false;
                                for(let j=0;j<discountOrderItem.length;j++){
                                    if(items[i].id == discountOrderItem[j].orderItem.id){
                                        items[i].discountForSecondQty = discountOrderItem[j].qty;
                                        items[i].isDiscountForSecond = true;
                                    }
                                }
                            }

                            this.choiceArr = items;

                            this.totalPrice = {
                                count:    resBody.count, // 总数量
                                total:    resBody.total, // 总计金额
                                discount: resBody.discount, // 优惠金额
                                amount:   resBody.amount, // 最终价格
                                removeZero:   resBody.removeZero // 最终价格
                            };
                        });
                    })
                }
                // 
            }).catch(()=>{
                console.log(this.curSelCouponId);
            })
            }else{
                if( sessionStorage.getItem('ordersId') ) {
                    this.orderId = sessionStorage.getItem('ordersId');
                    console.log("curSelectVipData",this.curSelectVipData)
                    let vipDataId = (this.curSelectVipData&&this.curSelectVipData.id)?this.curSelectVipData.id:'';
                    this.$http.put('orders/'+this.orderId+'/relieveMember?memberId='+vipDataId).then((res)=>{
                        this.curSelectVipData = '';
                        this.$http.get('orders/'+this.orderId).then((ress)=>{
                            if(!ress.data.id){
                                sessionStorage.removeItem("ordersId");
                                this.clearOrder();
                                return;
                            }
                            let resBody = ress.data;

                            let items = resBody.items;
                            let discountOrderItem = ress.data.discountOrderItem;
                                    
                            for(let i=0;i<items.length;i++){
                                items[i].isDiscountForSecond = false;
                                for(let j=0;j<discountOrderItem.length;j++){
                                    if(items[i].id == discountOrderItem[j].orderItem.id){
                                        items[i].discountForSecondQty = discountOrderItem[j].qty;
                                        items[i].isDiscountForSecond = true;
                                    }
                                }
                            }

                            this.choiceArr = items;

                            this.totalPrice = {
                                count:    resBody.count, // 总数量
                                total:    resBody.total, // 总计金额
                                discount: resBody.discount, // 优惠金额
                                amount:   resBody.amount, // 最终价格
                                removeZero:   resBody.removeZero // 最终价格
                            };
                        });
                    })
                }
            }
            
        },
       
        // 选择小类商品
        selSmallGoodType: function ( index, smallIdx ) {
            this.curIdx = index;
            this.curSmallTypeIdx = smallIdx;
            this.curSelectGoodsData = this.goodsData[index].subTypes[smallIdx];
        },
        //选择充值规则进行充值
        choiceRules(item){
            if( item ){
                this.inputVipMoney = '';//防止用户填了自定义充值，但结果选了冲送规则。
            }else {
                if(!/^(0|[1-9][0-9]{0,9})(\.[0-9]{1,2})?$/.test(this.inputVipMoney)|| this.inputVipMoney == 0){
                    this.$message({
                        message: '充值金额输入有误',
                        showClose: true,
                        type: 'error'
                    });
                    return;
                }
                let rechargeLimit = JSON.parse(sessionStorage.getItem("rechargeLimit"));
                if(Number(this.inputVipMoney)<Number(rechargeLimit)){
                    this.$message({
                        message: '充值金额不能小于'+Number(rechargeLimit)+'元',
                        showClose: true,
                        type: 'error'
                    });
                    return;
                }
            }
            this.payVipType = 'CASH';
            let userName = sessionStorage.getItem("userName");
            let sendBody = {
                "storeId": this.storeId,
                "memberId": this.curSelectVipData.id,
                "amount": parseFloat(this.inputVipMoney?this.inputVipMoney:item.depositAmount),
                "chargeRuleId": this.inputVipMoney?'':item.id,
                "type":"POS",
                userName
            }
            this.$http.put('member-charges/'+this.$uuid(),sendBody).then((res)=>{
                this.vipObj = item?item:{};
                this.$set(this.vipObj, 'code', res.data.code);
                this.$set(this.vipObj, 'ordersId', res.data.id);
                this.$set(this.vipObj, 'amount', res.data.amount);
            })
            this.vipPayBtn = true;
        },
       
        //点击会员列表，选择确定当前会员
        addVipFn(item){
            this.curBindCoupon = [];//清除会员已经绑好的优惠券
            this.vipANDdata(item);//绑定会员和当前订单
            this.curSelectVipData = item;
            this.curSelectVipData.amount = this.curSelectVipData.amount.toFixed(2);
            this.addVipBtn = false;
        },
        // 获取商品列表
        getGoods(){
            if ( !this.storeId ) {
                return;
            }
            this.$http.get('index?storeId='+ this.storeId).then((res)=>{
                if ( !res.data || !res.data[0] ) {
                    return;
                }
                let rentCates = [];
                let normalCates = [];
                if(res.data && Array.isArray(res.data) && res.data.length){
                    res.data.forEach((it,ind)=>{
                        if(it.leaseEnabled){
                            if(it.products && Array.isArray(it.products) && it.products.length){
                                it.products.forEach(ite=>{
                                    ite.productStatus = "ON";
                                    ite.leaseEnabled = true;
                                })
                            }
                            rentCates.push(it);
                        }else{
                            normalCates.push(it);
                        }
                    })
                    normalCates.forEach(it=>{
                        if(it.subTypes && Array.isArray(it.subTypes) && it.subTypes.length){
                            let subTypes = JSON.parse(JSON.stringify(it.subTypes));
                            subTypes.sort((a,b)=>{
                                return a.sequence - b.sequence;
                            });
                            it.subTypes = subTypes;
                        }
                    })
                    
                }
                console.log("klsdjfklsdjgklsdfj",res.data);
                if(this.leaseProductEnabled){
                    this.goodsData = [...normalCates,...rentCates];
                }else{
                    this.goodsData = [...normalCates];
                }
                console.log("goodsData",this.goodsData)
                this.rentCates = rentCates;
                this.curSelectGoodsData = this.goodsData[this.curIdx];
                $('.goods_type_nav .nav_text').css('height', '50px');
                $($('.goods_type_nav .nav_text')[this.curIdx]).css('height', 'auto');
            })
        },
          // 绑定会员和订单
        vipANDdata ( vipData ) {
            let vipDataId = (vipData&&vipData.id)?vipData.id:'';
            if( sessionStorage.getItem('ordersId') ){
                this.orderId = sessionStorage.getItem('ordersId');
                this.$http.put('orders/'+this.orderId+'/attachMember?memberId='+vipDataId).then((res)=>{
                    this.$message({
                        message: '成功绑定会员',
                        showClose: true,
                        type: 'success'
                    });
                    let body = res.data;

                    let items = body.items;
                    let discountOrderItem = res.data.discountOrderItem;
                            
                    for(let i=0;i<items.length;i++){
                        items[i].isDiscountForSecond = false;
                        for(let j=0;j<discountOrderItem.length;j++){
                            if(items[i].id == discountOrderItem[j].orderItem.id){
                                items[i].discountForSecondQty = discountOrderItem[j].qty;
                                items[i].isDiscountForSecond = true;
                            }
                        }
                    }

                    this.choiceArr = items;

                    this.totalPrice = {
                        count:    body.count, // 总数量
                        total:    body.total, // 总计金额
                        discount: body.discount, // 优惠金额
                        amount:   body.amount, // 最终价格
                        removeZero:   body.removeZero, // 最终价格
                    }
                })
            } else {
                this.orderId = '';
            }
        },
        cancelRentInfo(){
            this.rentForm = {
                name:"",
                mobile:"",
                empId:"",
                empName:"",
                ruleId:"",
                productId:"",
                areaId:"",
                tableNo:"",
                numId:"",
                source:"POS"
            }
            this.showRentInfo = false;
            this.nowSelRentRule = null;
        },
        sureSelRentInfo(){
            console.log(this.rentForm);
            if(!this.rentForm.numId){
                this.$message({
                    message: '请选择机位',
                    showClose: true,
                    type: 'error'
                });
                return;
            }
            if(!this.rentForm.mobile){
                this.$message({
                    message: '请填写顾客手机号',
                    showClose: true,
                    type: 'error'
                });
                return;
            }
            if ( !(/^1[3|4|5|6|7|8|9][0-9]{9}$/.test(this.rentForm.mobile)) ) {
                this.$message.error({
                    message: "请输入正确的手机号",
                    type: 'error'
                });
                return;
            }
            if(!this.rentForm.ruleId){
                this.$message({
                    message: '请选择计费规则',
                    showClose: true,
                    type: 'error'
                });
                return;
            }else{
                this.nowSelRentGoodsRules.forEach(it=>{
                    if(it.ruleId == this.rentForm.ruleId){
                        if(it.amount){
                            this.rentForm.authCode = "";
                            this.showPayCodeBoxForRent = true;
                            this.$forceUpdate();
                        }else{
                            this.rentForm.authCode = undefined;
                            this.confirmPaymentForRent();
                        }
                    }
                })
            }
        },
        changeRule(e){
            if(this.nowSelRentGoodsRules && Array.isArray(this.nowSelRentGoodsRules) && this.nowSelRentGoodsRules.length){
                this.nowSelRentGoodsRules.forEach(it=>{
                    if(it.ruleId == this.rentForm.ruleId){
                        this.nowSelRentRule = it;
                    }
                })
            }
        },
        confirmPaymentForRent(){
            // if(!this.rentForm.authCode){
            //     return;
            // }
            if(!this.canClick){
                return;
            }
            this.canClick = false;
            this.$http({
                url:`${API_BASE_URL}v1/call/create/lease/order`,
                method:"POST",
                data:{
                    ...this.rentForm,
                    storeId:this.storeId,
                }
            }).then(res=>{
                this.$message({
                    message: '操作成功',
                    showClose: true,
                    type: 'success'
                })
                // this.showPayLoding = true;
                this.cancelRentInfo();
                this.showPayCodeBoxForRent = false;
                setTimeout(()=>{
                    this.canClick = true;
                },500);
                console.log(res)
                this.curOrderData = res.data.leaseProductOrder;
                try {
                    this.printRentOrder();
                } catch (error) {
                    console.log(error)
                }
            }).catch(err=>{
                this.cancelRentInfo();
                this.showPayCodeBoxForRent = false;
                setTimeout(()=>{
                    this.canClick = true;
                },500);
            })
        },
        printRentOrder(){
            try {
                let printRentOrder = localStorage.getItem("printRentOrder");
                if(printRentOrder == "OFF"){
					console.log("不打印租赁单");
                    return;
                }
            } catch (error) {
                console.log(error);
            }
			console.log(this.curOrderData)
            if(!this.curOrderData){
                return;
            }
            var array =[];
            array = array.concat([28,38]);//打印汉字
            array = array.concat([29,33,17]);//汉字倍宽高
            // array = array.concat([27,33,8]);//加粗
            array = array.concat([27,97,49]);//居中
            array = array.concat(gbk(this.storeName+"(租赁单)"));
            array = array.concat([10]);//换行
            array = array.concat([27,97,48]);//左
            array = array.concat([29,33,0]);//取消汉字倍宽高
            array = array.concat(gbk('座位号:：'));
            array = array.concat([29,33,17]);
            if(this.curOrderData.numName != null){
                array = array.concat(gbk(this.curOrderData.numName));
            }
            array = array.concat([29,33,0]);
            array = array.concat([10]);//换行
            array = array.concat([29,33,8]);
            array = array.concat(gbk('订单号:：'+this.curOrderData.orderNum));
            array = array.concat([10]);//换行
            array = array.concat([27,33,0]);//取消加粗
            array = array.concat(gbk('开始时间:：'+new Date(this.curOrderData.addTime).Format('yyyy/MM/dd-hh:mm')));
            array = array.concat([10]);//换行
			array = array.concat(gbk('结束时间:：'+(['UNFINISHED',"FINISHED"].indexOf(this.curOrderData.status)!=-1?"租赁中":new Date(this.curOrderData.refundTime).Format('yyyy/MM/dd-hh:mm'))));
            array = array.concat([10]);//换行
            array = array.concat(gbk('打印时间:：'+new Date().Format('yyyy/MM/dd-hh:mm')));
            array = array.concat([10]);//换行
            array = array.concat(gbk('来源:：'+this.sourceType[this.curOrderData.source]));
            array = array.concat([10]);//换行
			array = array.concat(gbk('计费规则:：'+this.curOrderData.ruleName));
            array = array.concat([10]);//换行
            array = array.concat([27,100,2]);//空格走纸
            
            array = array.concat(gbk('租赁商品:：'+this.curOrderData.productName));
            array = array.concat([10]);//换行 
            array = array.concat(gbk('总支付押金金额:：'+Number(this.curOrderData.totalAmount).toFixed(2)));
            array = array.concat([10]);//换行

            array = array.concat([10]);//换行
            array = array.concat([27,100,2]);//空格走纸
            array = array.concat([27,100,2]);//空格走纸
  
            array = array.concat([27,105]);//切纸           
            array = array.concat([10]);//换行 
            //切纸结束
            
            //多份打印
            var arrays=[];
            for(var i = 0 ;i<this.printsNum;i++){
                  arrays = arrays.concat(array)
            }
			console.log("arrays",arrays);
            try {
                print_((localStorage.getItem('printIdForSale')?localStorage.getItem('printIdForSale'):''),arrays);//小票打印
            } catch (error) {
                
            }
		},
        // 选择商品
        choiceGoods( item ){
            console.log(item);
            // 
            if(item.hasOwnProperty("leaseEnabled") && item.leaseEnabled){
                this.showRentInfo = true;
                if(item.extras && Array.isArray(item.extras) && item.extras.length){
                    item.extras.forEach((it,ind)=>{
                        if(typeof it == "string"){
                            item.extras[ind] = JSON.parse(it);
                        }
                    })
                    this.nowSelRentGoodsRules = item.extras;
                }
                console.log(item);
                this.nowSelRentGoods = item;
                this.rentForm.productId = item.id;
                // 
                let storeInfo = sessionStorage.getItem("store");
                if(typeof storeInfo == "string"){
                    storeInfo = JSON.parse(storeInfo);
                }
                if(storeInfo){
                    this.rentForm.empId = storeInfo.employeeId;
                    this.rentForm.empName = storeInfo.employeeName;
                }
                return;
            }
            // 
            if(!this.canClick){
                // this.$message({
                //     message: "点击不能过快",
                //     showClose: true,
                //     duration:1000,
                //     type: 'error'
                // })
                return;
            }
            // 选择规格
            // if(item.specs && Array.isArray(item.specs) && item.specs.length){
            //     this.specs = item.specs;
            //     this.nowSelNeedSpecItem = item;
            //     this.showSelSpec = true;
            //     this.nowSelSpec = [];
            //     return
            // }
            if(item.productSpecs && Array.isArray(item.productSpecs) && item.productSpecs.length){
                let resetFlag = true;
                let seledItem = null;
                if(this.choiceArr && Array.isArray(this.choiceArr) && this.choiceArr.length){
                    this.choiceArr.forEach(it=>{
                        if(it.productId == item.id){
                            resetFlag = false;
                            seledItem = it;
                        }
                    })
                }
                if(item.productSpecs && Array.isArray(item.productSpecs)){
                    if(resetFlag){
                        let nowSelSpec = [];
                        item.productSpecs.forEach(it=>{
                            it.seledSpec = it.defaultSpec;
                            nowSelSpec.push(it.defaultSpec);
                        })
                        this.nowSelSpec = nowSelSpec;
                    }else{
                        if(seledItem && seledItem.specs && Array.isArray(seledItem.specs)){
                            item.productSpecs.forEach(it=>{
                                if(it.specs && Array.isArray(it.specs)){
                                    it.specs.forEach(ite=>{
                                        if(seledItem.specs.indexOf(ite)!=-1){
                                            it.seledSpec = ite;
                                        }
                                    })
                                }
                            })
                          this.nowSelSpec = seledItem.specs;
                        }
                    }
                }
                this.specs = item.productSpecs;
                this.nowSelNeedSpecItem = item;
                this.showSelSpec = true;
                return
            }
            // 选择规格end
            // 如果在选择支付方式界面，直接返回
            this.goodSearch = '';
            if ( this.upBtn ) return;
            if ( item.id == '0' ) {
                this.showCustomPrice = true;
                this.customPrice = '';
                setTimeout(()=>{
                    $('#customPriceInput').focus();
                })
                return;
            }
            if(item.openMatchEnabled){
                this.choiceItem = item;
            }else{
                this.choiceItem = null;
            }
            this.addProduct( item.id );
            this.canClick = false;
            setTimeout(()=>{
                this.canClick = true;
            },500);
        },
        // 确定自定义商品
        confirmCustomPrice: function () {
            if ( this.customPrice ) {
                this.customPrice = this.customPrice.replace(/\s+/g, "");
            }
            if ( !/^[0-9]*[1-9][0-9]*$/.test(this.customPrice) ) {
                this.$message({
                    message: '请输入正整数',
                    showClose: true,
                    type: 'error'
                })
                return;
            }
            this.addProduct( '0', this.customPrice);
            this.showCustomPrice = false;
        },
        // 增加数量
        addAmount: function ( item ) {
            console.log(item);
            // if(item.productSpecs && Array.isArray(item.productSpecs) && item.productSpecs.length){
            //     this.nowSelSpec = item.specs;
            //     if(item.specs && Array.isArray(item.specs)){
            //         item.productSpecs.forEach(it=>{
            //             it.specs.forEach(ite=>{
            //                 if(item.specs.indexOf(ite)!=-1){
            //                     it.seledSpec = ite;
            //                 }
            //             })
            //         })
            //     }
            //     this.specs = item.productSpecs;
            //     this.nowSelNeedSpecItem = item;
            //     item.id = item.productId;
            //     item.name = item.productName;
            //     this.showSelSpec = true;
            //     return;
            // }  
            if(item.productSpecs && Array.isArray(item.productSpecs) && item.productSpecs.length){
                this.nowSelSpec = item.specs;
                this.fromSelSpec = true;
            }
            if(!this.canClick){
                // this.$message({
                //     message: "点击不能过快",
                //     showClose: true,
                //     duration:1000,
                //     type: 'error'
                // })
                return;
            }
            if ( this.upBtn ) return;
            if ( item.productId == '0' ) return;
            this.addProduct( item.productId );
            this.canClick = false;
            setTimeout(()=>{
                this.canClick = true;
            },500);
        },
        // 减少数量
        reduceAmount: function ( item ) {
            this.nowReduceItem = item;
            if(!this.canClick){
                // this.$message({
                //     message: "点击不能过快",
                //     showClose: true,
                //     duration:1000,
                //     type: 'error'
                // })
                return;
            }
            if ( this.upBtn ) return;
            this.reduceProduct( item.productId );

            this.canClick = false;
            setTimeout(()=>{
                this.canClick = true;
            },500);
        },
        
        // 添加商品
        addProduct: function ( productId, isCustom ) {
            if ( !this.addGoodBtn ) {
                return;
            }
            this.addGoodBtn = false;
            let data = {
                "productId": productId,
                "productCount": 1,
                specs:this.fromSelSpec?this.nowSelSpec:undefined
            }
            if ( isCustom ) {
                data = {
                    "productId": productId,
                    "productCount": 1,
                    "amount": this.customPrice
                }
            }
            if(sessionStorage.getItem('ordersId')){
                //有本地id就赋值 ，
                this.orderId = sessionStorage.getItem('ordersId')
            }else{
                //没有就新建id
                let workShiftData = JSON.parse(sessionStorage.getItem("workshift"));
                // let userName = workShiftData.operatorName;
                let userName = sessionStorage.getItem("userName");
                let url='?createTime='+new Date().getTime()+'&storeId='+this.storeId+'&userName='+userName;
                if( this.curSelectVipData ){
                    url+='&memberId='+this.curSelectVipData.id
                }
                this.$http.put('/create-orders'+url).then((res)=>{
                    sessionStorage.setItem('ordersId',res.data.id);
                    this.orderId = res.data.id;
                    this.code = res.data.code;
                    this.$http.post('orders/' + this.orderId + '/add', data).then((res)=>{
                        // 
                        try {
							let pId = `${this.nowSelSpec}_&_${productId}`;
							if(res.data.items && Array.isArray(res.data.items) && res.data.items.length){
								res.data.items.forEach(it=>{
									if((`${it.specs}_&_${it.productId}` == pId && it.matchEnabled) || (it.productId==productId && it.matchEnabled)){
										this.doShowPeiGoods(it);
									}
								})
							}
						} catch (error) {
							console.log(error);
						}
                        // 
                        this.fromSelSpec = false;
                        this.showSelSpec = false;
                        let body = res.data;
                        // let discountOrderItem = body.discountOrderItem;
                        let items = body.items;
                        // for(let i=0;i<items.length;i++){
                        //     items[i].isDiscountForSecond = false;
                        //     for(let j=0;j<discountOrderItem.length;j++){
                        //         if(items[i].productId == discountOrderItem[j].productId){
                        //             items[i].discountForSecondQty = discountOrderItem[j].qty;
                        //             items[i].isDiscountForSecond = true;
                        //         }
                        //     }
                        // }
                        let discountOrderItem = res.data.discountOrderItem;
                        
                        for(let i=0;i<items.length;i++){
                            items[i].isDiscountForSecond = false;
                            for(let j=0;j<discountOrderItem.length;j++){
                                if(items[i].productId == discountOrderItem[j].productId){
                                    items[i].discountForSecondQty = discountOrderItem[j].qty;
                                    items[i].isDiscountForSecond = true;
                                }
                            }
                        }
                        console.log(items)
                        this.choiceArr = items;
                        this.totalPrice = {
                            count:    body.count, // 总数量
                            total:    body.total, // 总计金额
                            discount: body.discount, // 优惠金额
                            amount:   body.amount, // 最终价格
                            removeZero:   body.removeZero, // 最终价格
                        }
                        for (let i = 0, len = this.pageSize - this.choiceArr.length; i < len; i++) {
                            this.choiceArr.push({});
                        }
                        this.addGoodBtn = true;
                        // 
                        if(this.choiceItem && this.choiceItem.openMatchEnabled){
                            let tempItem = null;
                            if(items && Array.isArray(items) && items.length){
                                items.forEach(it=>{
                                    if(it.productId == this.choiceItem.id){
                                        tempItem = it;
                                    }
                                })
                            }
                            console.log(tempItem)
                            if(tempItem){
                                // this.doShowPeiGoods({...tempItem,openMatchEnabled:this.choiceItem.openMatchEnabled});

                            }
                        }
                        // 
                    }).catch( ( err )=>{
                        this.addGoodBtn = true;
                        this.fromSelSpec = false;
                        this.showSelSpec = false;
                        if ( err.response.status === 400 ) {
                            this.searchOrderType();
                        }
                    })
                })
                return;
            }
            this.$http.post('orders/' + this.orderId + '/add', data).then((res)=>{
                // 
                try {
                    let pId = `${this.nowSelSpec}_&_${productId}`;
                    if(res.data.items && Array.isArray(res.data.items) && res.data.items.length){
                        res.data.items.forEach(it=>{
                            if((`${it.specs}_&_${it.productId}` == pId && it.matchEnabled) || (it.productId==productId && it.matchEnabled)){
                                this.doShowPeiGoods(it);
                            }
                        })
                    }
                } catch (error) {
                    console.log(error);
                }
                // 
                this.fromSelSpec = false;
                this.showSelSpec = false;
                let body = res.data;
                let items = body.items;
                let discountOrderItem = body.discountOrderItem;
                for(let i=0;i<items.length;i++){
                    items[i].isDiscountForSecond = false;
                    for(let j=0;j<discountOrderItem.length;j++){
                        // if(items[i].productId == discountOrderItem[j].productId){
                        if(items[i].id == discountOrderItem[j].orderItem.id){
                            items[i].discountForSecondQty = discountOrderItem[j].qty;
                            items[i].isDiscountForSecond = true;
                            // if((items[i].specs&&Array.isArray(items[i].specs)&&items[i].specs.length) && (discountOrderItem[j].specs && Array.isArray(discountOrderItem[j].specs) && discountOrderItem[j].specs.length)){
                            //     discountOrderItem[j].forEach(it=>{
                            //         if(items[i].id == it.orderItem.id){
                            //             items[i].discountForSecondQty = discountOrderItem[j].qty;
                            //             items[i].isDiscountForSecond = true; 
                            //         }
                            //     })
                            // }else{
                            //     items[i].discountForSecondQty = discountOrderItem[j].qty;
                            //     items[i].isDiscountForSecond = true;
                            // }
                        }
                    }
                }
                this.choiceArr = items;
                this.totalPrice = {
                    count:    body.count, // 总数量
                    total:    body.total, // 总计金额
                    discount: body.discount, // 优惠金额
                    amount:   body.amount, // 最终价格
                    removeZero:   body.removeZero, // 最终价格
                }
                for (let i = 0, len = this.pageSize - this.choiceArr.length; i < len; i++) {
                    this.choiceArr.push({});
                }
                this.addGoodBtn = true;
                // 
                // 
                if(this.choiceItem && this.choiceItem.openMatchEnabled){
                    let tempItem = null;
                    if(items && Array.isArray(items) && items.length){
                        items.forEach(it=>{
                            if(it.productId == this.choiceItem.id){
                                tempItem = it;
                            }
                        })
                    }
                    console.log(tempItem)
                    if(tempItem){
                        this.doShowPeiGoods({...tempItem,openMatchEnabled:this.choiceItem.openMatchEnabled});
                    }
                }
                // 
                // 
            }).catch( ( err )=>{
                this.addGoodBtn = true;
                this.fromSelSpec = false;
                this.showSelSpec = false;
                if ( err.response.status === 400 ) {
                    this.searchOrderType();
                }
            })
        },
        // 添加商品
        addProductForMutil: function ( item,count ) {
            console.log(item)
            if(!/^-?[1-9]\d*$/.test(count)){
                this.$message({
                    message: '数量输入有误',
                    showClose: true,
                    type: 'error'
                })
                return;
            }
            if(count>99999){
                this.$message({
                    message: '数量输入超限',
                    showClose: true,
                    type: 'error'
                })
                return;
            }
            if((Number(item.quantity)+Number(count))<1){
                this.$message({
                    message: '数量输入有误',
                    showClose: true,
                    type: 'error'
                })
                return;
            }
            let data = {
                "productId": item.productId,
                "productCount": count,
                specs:(item.specs&&Array.isArray(item.specs)&&item.specs.length)?item.specs:undefined
            }
            
            if(sessionStorage.getItem('ordersId')){
                //有本地id就赋值 ，
                this.orderId = sessionStorage.getItem('ordersId')
            }else{
                //没有就新建id
                let workShiftData = JSON.parse(sessionStorage.getItem("workshift"));
                // let userName = workShiftData.operatorName;
                let userName = sessionStorage.getItem("userName");
                let url='?createTime='+new Date().getTime()+'&storeId='+this.storeId+'&userName='+userName;
                if( this.curSelectVipData ){
                    url+='&memberId='+this.curSelectVipData.id
                }
                this.$http.put('/create-orders'+url).then((res)=>{
                    sessionStorage.setItem('ordersId',res.data.id);
                    this.orderId = res.data.id;
                    this.code = res.data.code;
                    this.$http.post('orders/' + this.orderId + '/add', data).then((res)=>{
                        let body = res.data;
                        
                        let items = body.items;
                        let discountOrderItem = res.data.discountOrderItem;
                                
                        for(let i=0;i<items.length;i++){
                            items[i].isDiscountForSecond = false;
                            for(let j=0;j<discountOrderItem.length;j++){
                                if(items[i].productId == discountOrderItem[j].productId){
                                    items[i].discountForSecondQty = discountOrderItem[j].qty;
                                    items[i].isDiscountForSecond = true;
                                }
                            }
                        }

                        this.choiceArr = items;

                        this.totalPrice = {
                            count:    body.count, // 总数量
                            total:    body.total, // 总计金额
                            discount: body.discount, // 优惠金额
                            amount:   body.amount, // 最终价格
                            removeZero:   body.removeZero, // 最终价格
                        }
                        for (let i = 0, len = this.pageSize - this.choiceArr.length; i < len; i++) {
                            this.choiceArr.push({});
                        }
                        this.addGoodBtn = true;
                        this.showMultiCount = false;
                        this.mutilCount = "";
                    }).catch( ( err )=>{
                        this.addGoodBtn = true;
                        this.showMultiCount = false;
                        this.mutilCount = "";
                        if ( err.response.status === 400 ) {
                            this.searchOrderType();
                        }
                    })
                })
                return;
            }
            this.$http.post('orders/' + this.orderId + '/add', data).then((res)=>{
                let body = res.data;
                let items = body.items;
                let discountOrderItem = res.data.discountOrderItem;
                        
                for(let i=0;i<items.length;i++){
                    items[i].isDiscountForSecond = false;
                    for(let j=0;j<discountOrderItem.length;j++){
                        if(items[i].productId == discountOrderItem[j].productId){
                            items[i].discountForSecondQty = discountOrderItem[j].qty;
                            items[i].isDiscountForSecond = true;
                        }
                    }
                }

                this.choiceArr = items;

                this.totalPrice = {
                    count:    body.count, // 总数量
                    total:    body.total, // 总计金额
                    discount: body.discount, // 优惠金额
                    amount:   body.amount, // 最终价格
                    removeZero:   body.removeZero, // 最终价格
                }
                for (let i = 0, len = this.pageSize - this.choiceArr.length; i < len; i++) {
                    this.choiceArr.push({});
                }
                this.addGoodBtn = true;
                this.showMultiCount = false;
                this.mutilCount = "";
            }).catch( ( err )=>{
                this.addGoodBtn = true;
                if ( err.response.status === 400 ) {
                    this.searchOrderType();
                }
                this.showMultiCount = false;
                this.mutilCount = "";
            })
        },
        // 减少商品
        reduceProduct: function ( productId ) {
            // 
            console.log(this.curBindCoupon)
            if(this.curBindCoupon.length){
                this.$message({
                    message: '请先取消绑定优惠券，才能进行此操作。',
                    showClose: true,
                    type: 'error'
                })
                return;
            }
            // 
            if ( !this.reduceGoodBtn ) {
                return;
            }
            this.reduceGoodBtn = false;
            this.$http.post('orders/' + this.orderId + '/remove', {
                "productId": productId,
                "productCount": 1,
                "couponInstanceCode":this.curCouponData.code,
                specs:(this.nowReduceItem.specs&&Array.isArray(this.nowReduceItem.specs)&&this.nowReduceItem.specs.length)?this.nowReduceItem.specs:undefined
            }).then((res)=>{
                let body = res.data;
                if(body==''){
                    //订单已经删除
                    sessionStorage.removeItem('ordersId');
                    this.curBindCoupon = [];
                    this.orderId = ''; 
                    this.choiceArr = [{},{},{},{},{}];
                    this.totalPrice = {
                        count: 0, // 总数量
                        total: 0, // 总计金额
                        discount: 0, // 优惠金额
                        amount: 0, // 最终价格
                        removeZero: 0, // 抹零
                    };
                    this.reduceGoodBtn = true;
                    return;
                }

                let items = body.items;
                let discountOrderItem = res.data.discountOrderItem;
                        
                for(let i=0;i<items.length;i++){
                    items[i].isDiscountForSecond = false;
                    for(let j=0;j<discountOrderItem.length;j++){
                        if(items[i].id== discountOrderItem[j].orderItem.id){
                            items[i].discountForSecondQty = discountOrderItem[j].qty;
                            items[i].isDiscountForSecond = true;
                        }
                    }
                }

                this.choiceArr = items;

                this.totalPrice = {
                    count: body.count, // 总数量
                    total: body.total, // 总计金额
                    discount: body.discount, // 优惠金额
                    amount: body.amount, // 最终价格
                    removeZero: body.removeZero, // 最终价格
                }
                this.curBindCoupon = body.couponInstances;
                for (let i = 0, len = this.pageSize - this.choiceArr.length; i < len; i++) {
                    this.choiceArr.push({});
                }
                this.reduceGoodBtn = true;
                // // 
                // if ( sessionStorage.getItem('ordersId') ) {
                //     this.orderId = sessionStorage.getItem('ordersId');
                //     this.$http.get('orders/'+this.orderId).then((res)=>{
                //         let body = res.data;
                //         this.curBindCoupon = body.couponInstances;
                //         this.code = body.code;
                //         if ( !body ) {
                //             return;
                //         }
                //         this.choiceArr  = body.items;
                //         this.totalPrice = {
                //             count:    body.count, // 总数量
                //             total:    body.total, // 总计金额
                //             discount: body.discount, // 优惠金额
                //             amount:   body.amount, // 最终价格
                //         }
                //         this.vipName = body.memberName;
                //         for (let i = 0, len = this.pageSize - this.choiceArr.length; i < len; i++) {
                //             this.choiceArr.push({});
                //         }

                //         if ( res.data.memberId ) {
                //             this.getMemberData(res.data.memberId);
                //         }
                //     });
                // }
                // // 
            }).catch(( err )=>{
                this.reduceGoodBtn = true;
                if ( err.response.status === 400 ) {
                    this.searchOrderType();
                }
            })
        },
        // 选择支付方式
        shopUpBox(boo){
            if ( !(this.choiceArr[0].productName) ) {
                return;
            }
            this.payType = 'CASH';
            if(this.curSelectVipData&&this.curSelectVipData.amount>=this.totalPrice.amount){
                this.payType = 'MEMBER';
            }
            //挂单弹出框
            this.upBtn = boo;
            console.log("打开支付方式界面后默认支付方式为："+this.payType);
        },
        shopUpBoxForReturnMoney(boo){
            if ( !(this.choiceArr[0].productName) ) {
                return;
            }
            this.payType = 'CASH';
            if(this.curSelectVipData&&this.curSelectVipData.amount>=this.totalPrice.amount){
                this.payType = 'MEMBER';
            }
            //挂单弹出框
            this.upBtn = boo;
            console.log("打开支付方式界面后默认支付方式为："+this.payType);
            this.$http({
                url:"return-order",
                method:"POST",
                data:{
                    orderId:this.orderId
                }
            }).then(res=>{
                console.log(res);
                if(res.data.result.code == 200){
                    let body = res.data.data;

                    let items = body.items;
                    let discountOrderItem = res.data.discountOrderItem;
                            
                    for(let i=0;i<items.length;i++){
                        items[i].isDiscountForSecond = false;
                        for(let j=0;j<discountOrderItem.length;j++){
                            if(items[i].id == discountOrderItem[j].orderItem.id){
                                items[i].discountForSecondQty = discountOrderItem[j].qty;
                                items[i].isDiscountForSecond = true;
                            }
                        }
                    }

                    this.choiceArr = items;

                    this.totalPrice = {
                        count:    body.count, // 总数量
                        total:    body.total, // 总计金额
                        discount: body.discount, // 优惠金额
                        amount:   body.amount, // 最终价格
                        removeZero:   body.removeZero, // 最终价格
                    }
                    let nowCurBindCoupon = JSON.parse(sessionStorage.getItem('nowCurBindCoupon'));
                    if(nowCurBindCoupon.length){
                        this.curBindCoupon = [];
                    }
                }else if(res.data.result.code == 400){
                    this.clearOrder();
                }
            });
        },
        //会员充值
        vipPayFn(){
            this.canDeletepayment = false;
            if ( !this.payCode && this.payVipType == 'PAYCARD'  ) {
                this.$message({
                    message: '请输入收款码',
                    showClose: true,
                    type: 'error'
                })
                return;
            }
            if ( !this.payApiBtn ) {
                return;
            }
            this.payApiBtn = false;
            this.showPayCodeBox = false;
            this.showPayLoding = true;
            if ( this.payVipType !== "PAYCARD" ) {
                this.payCode = '';
            }
            if ( this.vipObj.amount <= 0 ) {
                return;
            }
            this.$http.put('payments/' + this.$uuid(), {
                "orderId": this.vipObj.ordersId,
                "channel": this.payVipType,
                "amount":  this.vipObj.amount,
                "authCode": this.payCode,
            }).then((res)=>{
                this.payCode = '';
                if ( res.status === 202 && this.payVipType == 'PAYCARD' ) {
                    let overTimeNum = 0;
                    let curOrderId = this.vipObj.ordersId;

                    this.delPaymentLodingTimer();
                    this.payLoadTimer = setInterval(()=>{
                        overTimeNum += 2;
                        let that = this;
                        if ( overTimeNum >= 180 ) { // 超过180秒，取消订单
                            clearInterval(this.payLoadTimer);
                            // this.payApiBtn = true;
                            // this.showPayLoding = false;
                            // this.showRechargeBox = false;
                            // this.$message({
                            //     message: '支付超时，当前订单已取消！',
                            //     showClose: true,
                            //     type: 'error'
                            // })
                            // this.deletePayment( curOrderId );
                            return;
                        }
                        this.payLoad(curOrderId, function () {
                            clearInterval(that.payLoadTimer);
                            that.payVoice("success",that.vipObj.amount);
							// var iframe = "<iframe id='iframes' height='0' width='0' src='"+API_BASE_URL+"v1/pos/speech?tex=成功到账"+that.vipObj.amount+"元&vol=9&per=0&spd=5&pit=5' frameborder='0'></iframe>";
	                        // $('#cashier').append(iframe)
	                        // setTimeout(()=>{
	                        //     $("#iframes").remove();
	                        // },8000)
//                          that.voice_text = '成功到账'+that.vipObj.amount+'元';
//                          setTimeout(()=>{
//                              $('#speech_voice').speech({
//                                  "speech": false,
//                                  "speed": 3,
//                              });
//                          })
                            that.getMemberData(that.curSelectVipData.id);
                            that.$message({
                                message: '充值成功',
                                showClose: true,
                                type: 'success'
                            });
                            that.showRechargeBox = false;
                            that.vipPayBtn = false;
                            that.showPayLoding = false;
                            that.showOnLinePaySuccessMask = true;
                            that.inputVipMoney = '';
                            setTimeout(()=>{
                                that.payApiBtn = true;
                            }, 300);
                            
                        })
                    }, 2000)
                } else {
                    if ( this.payVipType == 'PAYCARD' ) {
                        this.showOnLinePaySuccessMask = true;
                        this.payVoice("success",this.vipObj.amount);
                        // var iframe = "<iframe id='iframes' height='0' width='0' src='"+API_BASE_URL+"v1/pos/speech?tex=成功到账"+this.vipObj.amount+"元&vol=9&per=0&spd=5&pit=5' frameborder='0'></iframe>";
                        // $('#cashier').append(iframe)
                        // setTimeout(()=>{
                        //     $("#iframes").remove();
                        // },8000)
//                      this.voice_text = '成功到账'+this.vipObj.amount+'元';
//                      setTimeout(()=>{
//                          $('#speech_voice').speech({
//                              "speech": false,
//                              "speed": 3,
//                          });
//                      })
                    }
                    this.$message({
                        message: '充值成功',
                        showClose: true,
                        type: 'success'
                    });
                    this.payType = "MEMBER";
                    this.getMemberData(this.curSelectVipData.id);
                    this.showRechargeBox = false;
                    this.vipPayBtn = false;
                    this.showPayLoding = false;
                    this.inputVipMoney = '';
                    setTimeout(()=>{
                        this.payApiBtn = true;
                    }, 300)
                }
            }).catch(()=>{
                this.payCode = '';
                this.showPayLoding = false;
                this.payApiBtn = true;
            })
        },
        delPaymentLodingTimer: function () {
            setTimeout(()=>{
                this.delPaymentLodingTime--;
                if ( this.delPaymentLodingTime <= 0 ) {
                    this.canDeletepayment = true;
                    this.delPaymentLodingTime = 30;
                } else {
                    this.delPaymentLodingTimer();
                }
            },1000)
        },
        //备注
        orderNotes(){
            let body = {
                notes:this.notes
            }
            this.$http.post('orders/'+this.orderId+'/notes',body).then((res)=>{
                this.notes = '';
            })
        },
        // 
        convertCurrency(num) {
      const chineseNum = {
          digits: ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'],
          units: ['', '十', '百', '千'],
          bigUnits: ['', '万', '亿', '万亿']
      };

      function convertInteger(numStr) {
          if (numStr === '0') return '零';
          let result = '';
          let zeroCount = 0;
          const len = numStr.length;

          for (let i = 0; i < len; i++) {
              const digit = parseInt(numStr[i]);
              const pos = len - i - 1;
              const unitIndex = pos % 4;
              const bigUnitIndex = Math.floor(pos / 4);

              if (digit === 0) {
                  zeroCount++;
              } else {
                  if (zeroCount > 0) {
                      result += '零';
                      zeroCount = 0;
                  }
                  // 处理十位的特殊读法（例如：10读作"十"，110读作"一百一十"）
                  if (digit === 1 && unitIndex === 1 && i === 0) {
                      result += chineseNum.units[unitIndex];
                  } else {
                      result += chineseNum.digits[digit] + chineseNum.units[unitIndex];
                  }
              }

              // 添加大单位（万/亿）
              if (unitIndex === 0 && bigUnitIndex > 0) {
                  result += chineseNum.bigUnits[bigUnitIndex];
              }
          }

          return result.replace(/零+$/, '') || '零';
      }

      function convertDecimal(decimalStr) {
          return decimalStr.split('').map(c => chineseNum.digits[parseInt(c)]).join('');
      }

      // 主处理逻辑
      let numStr = typeof num === 'string' ? num : String(num);
      let isNegative = false;
      
      // 处理负数
      if (numStr.startsWith('-')) {
          isNegative = true;
          numStr = numStr.slice(1);
      }

      const [integerPart, decimalPart] = numStr.split('.');
      let result = convertInteger(integerPart || '0');

      // 处理小数部分
      if (decimalPart) {
          const isAllZero = decimalPart.split('').every(c => c === '0');
          if (!isAllZero) {
              result += '点' + convertDecimal(decimalPart);
          }
      }

      return (isNegative ? '负' : '') + result;
  },
        // convertCurrency(money) {
        //     //汉字的数字
        //     var cnNums = new Array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
        //     //基本单位
        //     var cnIntRadice = new Array('', '十', '百', '千');
        //     //对应整数部分扩展单位
        //     var cnIntUnits = new Array('', '万', '亿', '兆');
        //     //对应小数部分单位
        //     var cnDecUnits = new Array('', '', '毫', '厘');
        //     //整数金额时后面跟的字符
        //     var cnInteger = '';
        //     //整型完以后的单位
        //     var cnIntLast = '点';
        //     //最大处理的数字
        //     var maxNum = 999999999999999.9999;
        //     //金额整数部分
        //     var integerNum;
        //     //金额小数部分
        //     var decimalNum;
        //     //输出的中文金额字符串
        //     var chineseStr = '';
        //     //分离金额后用的数组，预定义
        //     var parts;
        //     if (money == '') { return ''; }
        //     money = parseFloat(money);
        //     if (money >= maxNum) {
        //         //超出最大处理数字
        //         return '';
        //     }
        //     if (money == 0) {
        //         chineseStr = cnNums[0] + cnIntLast + cnInteger;
        //         return chineseStr;
        //     }
        //     //转换为字符串
        //     money = money.toString();
        //     if (money.indexOf('.') == -1) {
        //         integerNum = money;
        //         decimalNum = '';
        //     } else {
        //         parts = money.split('.');
        //         integerNum = parts[0];
        //         decimalNum = parts[1].substr(0, 4);
        //     }
        //     //获取整型部分转换
        //     if (parseInt(integerNum, 10) > 0) {
        //         var zeroCount = 0;
        //         var IntLen = integerNum.length;
        //         for (var i = 0; i < IntLen; i++) {
        //             var n = integerNum.substr(i, 1);
        //             var p = IntLen - i - 1;
        //             var q = p / 4;
        //             var m = p % 4;
        //             if (n == '0') {
        //                 zeroCount++;
        //             } else {
        //                 if (zeroCount > 0) {
        //                     chineseStr += cnNums[0];
        //                 }
        //                 //归零
        //                 zeroCount = 0;
        //                 chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
        //             }
        //             if (m == 0 && zeroCount < 4) {
        //                 chineseStr += cnIntUnits[q];
        //             }
        //         }
        //         if(decimalNum!=''){
        //             chineseStr += cnIntLast;
        //         }
        //     }else{
        //         chineseStr+="零点";
        //     }
        //     //小数部分
        //     if (decimalNum != '') {
        //         var decLen = decimalNum.length;
        //         for (var i = 0; i < decLen; i++) {
        //             var n = decimalNum.substr(i, 1);
        //             if (n != '0') {
        //                 chineseStr += cnNums[Number(n)] + cnDecUnits[i];
        //             }else{
        //                 chineseStr+="零";
        //             }
        //         }
        //     }else{
        //         // chineseStr+="零零";
        //     }
        //     if (chineseStr == '') {
        //         chineseStr += cnNums[0] + cnIntLast + cnInteger;
        //     } else if (decimalNum == '') {
        //         chineseStr += cnInteger;
        //     }
        //     return chineseStr;
        // },
        generateMoneyNumVoice(numberStr){
            let voiceArr = [];
            if(numberStr){
            let numberArr = numberStr.split("");
            if(numberArr && Array.isArray(numberArr)){
                numberArr.forEach(it=>{
                voiceArr.push(`<audio style="display:none" id='paySucVoice' class="playRate" src='../../../static/voice/cgdz/${it}.mov'></audio>`);
                })
            }
            }
            return voiceArr;
        },
        payVoice(type,amount){
            let getAmount = Number(amount).toFixed(2);
            let cgdz = `<audio style="display:none" id='paySucVoice' src='../../../static/voice/cgdz/cgdz.mov'></audio>`;
            let yuan = `<audio style="display:none" id='paySucVoice' src='../../../static/voice/cgdz/yuan.mov'></audio>`;
            let errorVoice = `<audio style="display:none" id='paySucVoice' src='../../../static/voice/cgdz/zfsb.mp3'></audio>`;
            console.log(this.convertCurrency(Number(getAmount)));
            let moneyAudios = [];
            try {
                moneyAudios = this.generateMoneyNumVoice(this.convertCurrency(Number(getAmount)));
            } catch (error) {
                console.log(error)      
            }
            let audios = [cgdz,...moneyAudios,yuan];
            if(type == "error"){
                audios = [errorVoice];
            }
            if(audios && Array.isArray(audios) && audios.length){
                let audioIndex = 0;
                function playAudio(audioIndex){
                    if(audioIndex < audios.length){
                        $("#cashier").append(audios[audioIndex]);
                        console.log("正在播放"+audioIndex);
                        // 
                        let audioDevice = "";
                        audioDevice = localStorage.getItem("audioDevice");
                        try {
                            if(audioDevice){
                                console.log("paySucVoice",$("#paySucVoice")[0]);
                                console.log(`pay audio is being output on ${audioDevice}`);
                                $("#paySucVoice")[0].setSinkId(audioDevice);
                            }
                        } catch (error) {
                            console.log("error",error);
                        }
                        $("#paySucVoice")[0].play();
                        // 
                        $("#paySucVoice").on("playing",function () {
                        try {
                            let payVoiceVolum  = localStorage.getItem("payVoiceVolum");
                            if(payVoiceVolum){
                                console.log("payVoiceVolum",payVoiceVolum)
                                $("#paySucVoice")[0].volume = Number(JSON.parse(payVoiceVolum) / 100).toFixed(2);
                            }
                            if($(this).hasClass("playRate")){
                            // $(this)[0].playbackRate = 1;
                            }
                        } catch (error) {
                            console.log("error",error);
                        }
                        })
                        $("#paySucVoice").on("ended",function () {
                            this.remove();
                            playAudio(audioIndex+1);
                        })
                    }else{
                        console.log("播放完毕");
                        audios = [];
                        $("#paySucVoice").remove();
                    }
                }
                playAudio(audioIndex);
                setTimeout(() => {
                    $("#paySucVoice").remove();
                }, 15000);
                return;
            }
        },
        // payVoice(type,amount){
        //     // 
        //     try {
        //         $('.payAudio').remove();
        //     } catch (error) {
                
        //     }
        //     let audio = `<audio style="display:none;" controls="" class="payAudio" src="${API_BASE_URL}v1/pos/speech?tex=成功到账${amount}元&vol=9&per=0&spd=5&pit=5" id="ipAudio"></audio>`; 
        //     if(type == "error"){
        //         audio = `<audio style="display:none;" controls="" class="payAudio" src="${API_BASE_URL}v1/pos/speech?tex=支付失败,请重新支付&vol=9&per=0&spd=5&pit=5" id="ipAudio"></audio>`; 
        //     }
        //     $('#cashier').append(audio);
        //     // 
        //     setTimeout(()=>{
        //         let audioDevice = "";
        //         audioDevice = localStorage.getItem("audioDevice");
        //         if(audioDevice){
        //             console.log("$.payAudio",$(".payAudio")[0]);
        //             console.log(`pay audio is being output on ${audioDevice}`);
        //             $(".payAudio")[0].setSinkId(audioDevice);
        //         }
        //         $(".payAudio")[0].play();
        //         // 
        //         $(".payAudio").on("playing",function () {
        //             let payVoiceVolum  = localStorage.getItem("payVoiceVolum");
        //             if(payVoiceVolum){
        //                 console.log("payVoiceVolum",payVoiceVolum)
        //                 $(".payAudio")[0].volume = Number(JSON.parse(payVoiceVolum) / 100).toFixed(2);
        //             }
        //         })
        //         $(".payAudio").on("ended",function () {
        //             this.remove();
        //         })
        //         setTimeout(()=>{
        //             try {
        //                 $(".payAudio").remove();
        //             } catch (error) {
                        
        //             }
        //         },9000)
        //     },100)
            
        // },
        // 确认支付
        confirmPayment: function () {
            
            // if(this.curSelectVipData.id){
            //     if(this.payType != "MEMBER" && this.payVipType != 'PAYCARD'){
            //         // this.$message({
            //         //     message: '会员只能选择会员支付，提醒会员',
            //         //     showClose: true,
            //         //     duration:5000,
            //         //     type: 'error'
            //         // })
            //         return;
            //     }
            // }
            
            
            console.log(this.curSelCouponId)
            if ( this.vipPayBtn ) {
                this.vipPayFn();
                return;
            }
            this.canDeletepayment = false;
            if(this.localPrintsBtn&&this.printsNum==''){
                this.$message({
                    message: '请输入打印份数',
                    showClose: true,
                    type: 'error'
                })
                return;
            }
            // 限制小票打印份数
            if(!/^[0-9]$/.test(this.printsNum)){
                this.$message({
                    message: '请输入正确的打印份数',
                    showClose: true,
                    type: 'error'
                })
                return;
            }
            // 限制小票打印份数
            if(this.printsNum>=4){
                this.$message({
                    message: '小票打印最多3张',
                    showClose: true,
                    type: 'error'
                })
                return;
            }
            // 
            if ( !this.payCode && this.payType == 'PAYCARD' ) {
                this.$message({
                    message: '请输入收款码',
                    showClose: true,
                    type: 'error'
                })
                this.openPayCodeBox('PAYCARD');
                return;
            }
            // 支付码过滤
            if(this.payType == 'PAYCARD'){
                if(!this.payCode || String(this.payCode).trim().length < 18){
                    this.$message({
                        message: '付款码不全，请重新扫码',
                        showClose: true,
                        duration:5900,
                        type: 'error'
                    });
                    this.payCode = "";
                    this.showPayCodeBox = false;
                    return;
                }
            }
            // 
            if ( !this.paymentBtn ) { // 不能支付
                return;
            }
            this.paymentBtn = false;
            this.showPayCodeBox = false;
            if ( this.payType !== "PAYCARD" ) {
                this.payCode = '';
            }
            let data = {
                "orderId": this.orderId,
                "channel": this.payType,
                "amount": (this.totalPrice.amount).toFixed(2),
                "authCode": this.payCode,
                "tableNo": this.tableNo,
                "notes": this.notes,
                "coupon":this.curSelCouponId
            }
            this.printData = {
                goodArr: this.choiceArr,
                count: this.totalPrice.count, // 总数量
                total: this.totalPrice.total, // 总计金额
                discount: this.totalPrice.discount, // 优惠金额
                removeZero: this.totalPrice.removeZero, // 优惠金额
                amount: this.totalPrice.amount, // 最终价格
                tableNo: this.tableNo,
                notes: this.notes,
                createTime:0,
                payType:""
            }
            if ( this.totalPrice.count <= 0 && this.totalPrice.total <= 0 ) {
                return;
            }
            this.showPayLoding = true; // 显示等待框

            this.$http.put('payments/' + this.$uuid(), data).then((res)=>{
                console.log(res.data)
                this.printData.createTime = res.data.createTime;
                if(res.data.items && Array.isArray(res.data.items) && res.data.items.length){
                    this.printData.goodArr = res.data.items;
                }
                if(res.data.payments && Array.isArray(res.data.payments) && res.data.payments.length){
                    this.printData.payType = res.data.payments[0].channel;
                }
                this.payCode = '';
                if ( res.status === 202 ) {
                    let overTimeNum = 0;
                    let curOrderId = this.orderId;

                    this.delPaymentLodingTimer();
                    this.payLoadTimer = setInterval(()=>{
                        overTimeNum += 2;
                        if ( overTimeNum >= 180 ) { // 超过180秒，取消订单
                            clearInterval(this.payLoadTimer);
                            // this.paymentBtn = true;
                            // this.showPayLoding = false;
                            // this.$message({
                            //     message: '支付超时，当前订单已取消！',
                            //     showClose: true,
                            //     type: 'error'
                            // })
                            // this.deletePayment( curOrderId );
                            // this.clearOrder();
                            return;
                        }
                        let that = this;
                        this.payLoad(curOrderId, function () {
                            clearInterval(that.payLoadTimer);
                            that.$message({
                                message: '支付成功！',
                                showClose: true,
                                type: 'success'
                            })
                            sessionStorage.removeItem("nowCurBindCoupon");
                            sessionStorage.removeItem("nowSelCouponItem");
                            sessionStorage.removeItem('ordersId');
                            // 支付成功后，获取商品列表
                            that.getGoods();
                            that.clearOrder();

                            that.showPayLoding = false;
                            that.showOnLinePaySuccessMask = true;
                            for(var k = 0;k<that.printData.goodArr.length;k++){
                                if(that.printData.goodArr[k].productTypeId&&that.printData.goodArr[k].productTypeId!='1'){
                                    that.isCostPrintBtn = true;
                                }
                            }
                            setTimeout(()=>{
                                that.paymentBtn = true;
                                //控制是否打印
                                if(that.localPrintsBtn&&that.printsNum!=''&&that.isCostPrintBtn){
                                    that.surePrint();
                                    that.isCostPrintBtn = false;
                                }
                                that.sureKitchenPrint();
                            }, 100)
                            let getAmount = (that.printData.amount).toFixed(2);
                            that.payVoice("success",getAmount);
							// var iframe = "<iframe id='iframes' height='0' width='0' src='"+API_BASE_URL+"v1/pos/speech?tex=成功到账"+getAmount+"元&vol=9&per=0&spd=5&pit=5' frameborder='0'></iframe>";
	                        // $('#cashier').append(iframe)
	                        // setTimeout(()=>{
	                        //     $("#iframes").remove();
                            // },8000)
                            that.curSelCouponId = [];
//                          that.voice_text = '成功到账'+that.printData.amount+'元';
//                          setTimeout(()=>{
//                              $('#speech_voice').speech({
//                                  "speech": false,
//                                  "speed": 3,
//                              });
//                          })
                        });
                    }, 2000)
                } else {
                    this.$message({
                        message: '支付成功！',
                        showClose: true,
                        type: 'success'
                    })
                    sessionStorage.removeItem('ordersId');
                    sessionStorage.removeItem("nowCurBindCoupon");
                    sessionStorage.removeItem("nowSelCouponItem");
                    // 支付成功后，获取商品列表
                    this.getGoods();
                    console.log('999');
                    this.curSelCouponId = [];
                    // $.get('https://tsn.baidu.com/text2audio?lan=zh&ctp=1&cuid=abcdxxx&tok=24.41033a259c20301114cb4997319428ca.2592000.1525010048.282335-11019528&tex=%E7%99%BE%E5%BA%A6%E4%BD%A0%E5%A5%BD&vol=9&per=0&spd=5&pit=5',function(yunyi){
                    //     console.log(yunyi)
                    // })
                    // 可能是现金支付处的到账语音
                    // var iframe = "<iframe id='iframes' height='0' width='0' src='"+API_BASE_URL+"v1/pos/speech?tex=成功到账"+this.printData.amount+"元&vol=9&per=0&spd=5&pit=5' frameborder='0'></iframe>";
                    //     $('#cashier').append(iframe)
                    //     console.log(iframe);
                    //     setTimeout(()=>{
                    //         $("#iframes").remove();
                    //     },8000)
                    if ( this.payType == 'PAYCARD' ) {
                        this.showOnLinePaySuccessMask = true;
                        this.payVoice("success",this.printData.amount);
						// var iframe = "<iframe id='iframes' height='0' width='0' src='"+API_BASE_URL+"v1/pos/speech?tex=成功到账"+this.printData.amount+"元&vol=9&per=0&spd=5&pit=5' frameborder='0'></iframe>";
                        // $('#cashier').append(iframe)
                        // setTimeout(()=>{
                        //     $("#iframes").remove();
                        // },8000)
//                      this.voice_text = '成功到账'+this.printData.amount+'元';
//                      setTimeout(()=>{
//                          $('#speech_voice').speech({
//                              "speech": false,
//                              "speed": 3,
//                          });
//                      })
                   }
                    // 更新订单
                    this.clearOrder();
                    // console.log(this.printData)
                    this.showPayLoding = false;
                    for(var k = 0;k<this.printData.goodArr.length;k++){
                        if(this.printData.goodArr[k].productTypeId&&this.printData.goodArr[k].productTypeId!='1'){
                            this.isCostPrintBtn = true;
                        }
                    }
                    setTimeout(()=>{
                        this.paymentBtn = true;
                        //控制是否打印
                        console.log("isCostPrintBtn",this.isCostPrintBtn);
                        console.log("localPrintsBtn",this.localPrintsBtn);
                        console.log("printsNum",this.printsNum);
                        if(this.localPrintsBtn&&this.printsNum!=''&&this.isCostPrintBtn){
                            this.surePrint();
                            this.isCostPrintBtn = false;
                        }
                        this.sureKitchenPrint();
                    }, 100)
                    
                }
            }).catch((err)=>{
                console.log("eefdwsgsdfhasdf",err);
                this.payCode = '';
                this.paymentBtn = true;
                this.showPayLoding = false;
                this.curSelCouponId = [];
                this.payVoice('error',0);
                // let iframe = "<iframe id='iframes-err' height='0' width='0' src='"+API_BASE_URL+"v1/pos/speech?tex=支付失败,请重新支付&vol=9&per=0&spd=5&pit=5' frameborder='0'></iframe>";
                // $('#cashier').append(iframe)
                // console.log(iframe)
                // setTimeout(()=>{
                //     $("#iframes-err").remove();
                // },8000);
                // this.$confirm('支付失败，请重新支付!', '注意', {
                //     confirmButtonText: '确定',
                //     cancelButtonText: '取消',
                //     type: 'warning',
                // }).then(() => {
                //     window.location.reload(true);
                // }).catch(() => {
                            
                // });
                if ( err.response.status === 400 ) {
                    // this.$message({
                    //     message: res.data,
                    //     showClose: true,
                    //     type: 'error'
                    // })
                    // window.location.reload(true);
                    this.$confirm(err.response.data, '注意', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                    }).then(() => {
                        window.location.reload(true);
                        this.searchOrderType();
                    }).catch(() => {
                        window.location.reload(true);
                        this.searchOrderType();
                    });
                }
                if(err.status !==200 ){
                    console.log("kkk")
                    // let tipText;
                    // err.response.data.message?tipText=err.response.data.message:tipText=err.response.data;
                    this.$confirm(err.response.data, '注意', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                    }).then(() => {
                        window.location.reload(true);
                    }).catch(() => {
                        window.location.reload(true);
                    });
                }
                
            })
        },
       
        createdOrdersId: function () {
            this.orderId = this.$uuid();
            this.$http.put('orders/' + this.orderId + '?storeId=' + this.storeId).then((res) => {
                sessionStorage.setItem('ordersId', this.orderId);
            }).catch(( err )=>{
                if ( err.response.status == 400 ) {
                    this.createdOrdersId();
                }
            })
        },
         // 刷新点单
        clearOrder: function () {
            this.closeVipFn();//删掉本地存储的会员信息
            this.payType = '';//重置支付方式
            this.tableNo = ''; // 重置座位号
            this.totalPrice = { // 重置
                count: 0, // 总数量
                total: 0, // 总计金额
                discount: 0, // 优惠金额
                amount: 0, // 最终价格
                removeZero: 0, // 最终价格
            };
            this.curSelectVipData = '';
            this.upBtn = false;
            if(!this.selNotes){
                this.notes = '';
            }
            // 生成新订单
            // this.createdOrdersId();
            this.choiceArr = [];
            this.curBindCoupon = []; // 清空选择的优惠券
            this.vipName = '';
            for (let i = 0; i < this.pageSize; i++) {
                this.choiceArr.push({});
            }
        },
        // 等待支付轮训接口
        payLoad: function ( orderId, fn ) {
            this.$http.get(API_BASE_URL+'v1/pay/micropay/query?orderId='+orderId).then((res)=>{
                if ( res.status === 200 ) {
                    fn();
                }
            }).catch(( err )=>{
                console.log("klklklkhjklhlkjhjlkj")
                console.log(err)
                this.payApiBtn = true;
                this.paymentBtn = true;
                this.showPayLoding = false;
                clearInterval(this.payLoadTimer);
                this.payVoice('error',0);
                // 
                // let iframe = "<iframe id='iframes-err' height='0' width='0' src='"+API_BASE_URL+"v1/pos/speech?tex=支付失败,请重新支付&vol=9&per=0&spd=5&pit=5' frameborder='0'></iframe>";
                // $('#cashier').append(iframe)
                // setTimeout(()=>{
                //     $("#iframes-err").remove();
                //     // window.location.reload(true);
                // },5000)
                // 
                setTimeout(()=>{
                    window.location.reload(true);
                },2000);
            })
        },
        // 初始化订单状态
        initOrder: function ( orderId ) {
            this.$http.put('orders/'+orderId+'/cancel').then((res)=>{

            })
        },
        // 打开在线支付框事件
        openPayCodeBox: function (str) {
            this.showPayCodeBox = true;
            this.payCode = '';
            this.payType = str;
            
            // console.log("修改了函数后："+this.payType);
            //如果支付码框为true时，判断当前payType是否为CASH，如为CASH则提示用户重新选择支付方式
            if(this.payType==='CASH'&&this.showPayCodeBox){
                console.log(this.payType);              
                this.$message({
                    message: "支付方式有误，请重新选择支付方式",
                    showClose: true,
                    type: 'error'
                });
                this.showPayCodeBox = false;
                this.payCode = '';
                // console.log("修改后："+this.payType);
                return;
            }
        },
        openPayCodeBoxForVip: function (strVip) {
            this.showPayCodeBox = true;
            this.payCode = '';
            this.payVipType = strVip;
            
            console.log("修改了函数后VIP支付方式："+this.payVipType);
            //如果支付码框为true时，判断当前payType是否为CASH，如为CASH则提示用户重新选择支付方式
            if(this.payVipType==='CASH'&&this.showPayCodeBox){
                console.log(this.payVipType);              
                this.$message({
                    message: "支付方式有误，请重新选择支付方式",
                    showClose: true,
                    type: 'error'
                });
                this.showPayCodeBox = false;
                this.payCode = '';
                console.log("修改后："+this.payVipType);
                return;
            }
        },
        newCreatOrderFn(){
            let createTime=new Date().getTime();
            let workShiftData = JSON.parse(sessionStorage.getItem("workshift"));
            let userName = workShiftData.operatorName;
            this.$http.put('/create-orders?createTime='+createTime+'&storeId='+this.storeId+'&userName='+userName).then((res)=>{
                this.orderId = res.data.id;
            })
        },
        //打印单据
        surePrint(){
            // if(!localStorage.getItem('printId')){
            //     alert('小票打印失败！请设置小票打印机ID');
            //     return;
            // }
            if ( localStorage.getItem('autoPrint')) {
                let  autoPrints = JSON.parse(localStorage.getItem('autoPrint'));
                autoPrints.placingOrder = this.printsNum;
                localStorage.setItem('autoPrint', JSON.stringify(autoPrints));
            };
            // this.$posPrint(parseInt(this.printsNum), document.getElementById("receipt").innerHTML, this.printData.goodArr);
             //销售小票
            var array =[];
            // 
            // array = array.concat([27,76]);//页模式
            // array = array.concat([27,87,0,0,0,0,72,2,176,2]);//起始位置
            // 
            array = array.concat([28,38]);//打印汉字
            // array = array.concat([29,33,34]);//汉字倍宽高
            // array = array.concat([27,33,8]);//加粗
            // array = array.concat([27,33,48]);
            array = array.concat([27,97,49]);//居中
            array = array.concat([29,33,17]);
            array = array.concat(gbk('欢迎光临'+this.storeName));
            // array = array.concat([29,33,17]);//汉字倍宽高
            array = array.concat([29,33,0]);
            array = array.concat([10]);//换行
            array = array.concat([10]);//换行
            array = array.concat([27,97,48]);//左
            array = array.concat([29,33,0]);//取消汉字倍宽高
            // array = array.concat([27,33,16]);//加粗
            array = array.concat(gbk('座位号:：'));
            array = array.concat([29,33,17]);
            // array = array.concat([27,33,8]);//加粗
            array = array.concat(gbk(this.printData.tableNo));
            array = array.concat([29,33,0]);
            array = array.concat([10]);//换行
            array = array.concat([27,33,0]);//取消加粗
            array = array.concat([29,33,8]);
            // 
            array = array.concat(gbk('流水号:：'+this.code));
            array = array.concat([10]);//换行
            array = array.concat(gbk('下单时间:：'+new Date(this.printData.createTime).Format('yyyy/MM/dd-hh:mm')));
            array = array.concat([10]);//换行
            array = array.concat(gbk('打印时间:：'+new Date().Format('yyyy/MM/dd-hh:mm')));
            array = array.concat([10]);//换行
            array = array.concat(gbk('创建人:：'+this.storeInfo.employeeName));
            array = array.concat([10]);//换行
            array = array.concat(gbk('支付方式:'+this.channelType[this.printData.payType]));
            array = array.concat([27,100,2]);//空格走纸
            console.log("this.printData.goodArr",this.printData.goodArr);
            for(var i=0;i<this.printData.goodArr.length;i++){
                if(this.printData.goodArr[i].id) {
                    array = array.concat(gbk('商品:：'+this.printData.goodArr[i].productName));
                    // if(this.printData.goodArr[i].specs && Array.isArray(this.printData.goodArr[i].specs) && this.printData.goodArr[i].specs.length){
                    //     let specs = this.printData.goodArr[i].specs.join("/");
                    //     array = array.concat(gbk("("+specs+")"));
                    // }
                    array = array.concat([10]);//换行
                    // 
                    if(this.printData.goodArr[i].specs && Array.isArray(this.printData.goodArr[i].specs) && this.printData.goodArr[i].specs.length){
                        let specs = this.printData.goodArr[i].specs.join("/");
                        array = array.concat(gbk('规格:：'+specs));
                        array = array.concat([10]);//换行  
                    }
                    // 
                    array = array.concat(gbk('数量:：'+this.printData.goodArr[i].quantity));
                    array = array.concat([10]);//换行                    
                    array = array.concat(gbk('单价:：'+(this.printData.goodArr[i].salesPrice/this.printData.goodArr[i].quantity).toFixed(2)));
                                       
                    if(this.printData.goodArr[i].masterItemDtos && Array.isArray(this.printData.goodArr[i].masterItemDtos) && this.printData.goodArr[i].masterItemDtos.length){
                        array = array.concat([10]);//换行 
                        this.printData.goodArr[i].masterItemDtos.forEach(it=>{
                            array = array.concat(gbk('---配品:：'+it.productName));
                            array = array.concat([10]);//换行
                            array = array.concat(gbk('---数量:：'+it.quantity));
                            array = array.concat([10]);//换行                    
                            array = array.concat(gbk('---单价:：'+(it.salesPrice/it.quantity).toFixed(2)));
                            array = array.concat([27,100,2]);//空格走纸
                            array = array.concat([10]);//换行 
                        });
                        console.log(this.printData.goodArr[i].masterItemDtos);
                    }else{
                        array = array.concat([27,100,2]);//空格走纸
                        array = array.concat([10]);//换行 
                    }

                }
            }
            array = array.concat(gbk('合计:：'+this.printData.total));
            array = array.concat([10]);//换行
            array = array.concat(gbk('总数:：'+this.printData.count));
            array = array.concat([10]);//换行
            array = array.concat(gbk('优惠:：'+(this.printData.discount).toFixed(2)));
            array = array.concat([10]);//换行
            array = array.concat(gbk('抹零:：'+(this.printData.removeZero).toFixed(2)));
            array = array.concat([10]);//换行
            array = array.concat(gbk('应付:：'+(this.printData.amount).toFixed(2)));
            array = array.concat([10]);//换行 
            array = array.concat([29,33,17]);
            array = array.concat(gbk('备注:：'+this.printData.notes));
            array = array.concat([29,33,0]);
            array = array.concat([10]);//换行
            array = array.concat([27,100,2]);//空格走纸
            array = array.concat([27,100,2]);//空格走纸
            // alert(array)
            //切纸
            // array = array.concat([10]);//换行 
            // array = array.concat([10]);//换行     
            // array = array.concat([27,100,2]);//空格走纸
            // array = array.concat([27,100,2]);//空格走纸
            array = array.concat([27,105]);//切纸           
            array = array.concat([10]);//换行 
            //切纸结束
            var arrays = [];
            for(var i = 0 ;i<this.printsNum;i++){
                  arrays = arrays.concat(array);
            }
            try {
                print_((localStorage.getItem('printIdForSale')?localStorage.getItem('printIdForSale'):''),arrays);
            } catch (error) {
                console.log(error);
            }
            console.log(this.printData)
            let newData = [];
            for(let j=0;j<this.printData.goodArr.length;j++){
                if(this.printData.goodArr[j].labelEnabled){
                    newData.push(this.printData.goodArr[j]);
                }
            }
            let labelPrintData = [];
            for(let i=0;i<newData.length;i++){
                if(newData[i].quantity==1){
                    labelPrintData.push(newData[i]);
                }else{
                    for(let y=0;y<newData[i].quantity;y++){
                        labelPrintData.push(newData[i]);
                    }
                }
            }
            if(JSON.parse(localStorage.getItem('isTagPrint'))&&(localStorage.getItem('printIdForTag')!="")){
                if(this.storeId == "a2bba1cc-ab27-11e8-9d74-f7accd960d1d"){
                    this.surePrintForTagForMuXueHuangHou(this.printData,labelPrintData);
                }else{
                    let makeEnabled = localStorage.getItem("makeEnabled");
                    if(makeEnabled==1){
                        this.surePrintForTagBig(this.printData,labelPrintData);
                    }else{
                        this.surePrintForTag(this.printData,labelPrintData);
                    }
                }
            }
        },
        surePrintForTagBig(data,labelPrintData){
            if(labelPrintData.length){
                console.log(labelPrintData);
                let makeIdsArr = [];
                let codesArr = [];
                labelPrintData[0].makeIds.forEach(it=>{
                    if(it.indexOf("-")!=-1 && Array.isArray(it.split("--")) && it.split("--").length>1 && it.split("--")[1]=="true"){
                        makeIdsArr.push(it.split("--")[0]);
                    }
                })
                labelPrintData[0].codes.forEach(it=>{
                    if(it.indexOf("-")!=-1 && Array.isArray(it.split("--")) && it.split("--").length>1 && it.split("--")[1]=="true"){
                        codesArr.push(it.split("--")[0]);
                    }
                });
                console.log("makeIdsArr",makeIdsArr);
                console.log("codesArr",codesArr);
                // 遍历商品数据
                for(let i=0;i<labelPrintData.length;i++){
                    // let labelPrintFlag = true;
                    // let splitArr = labelPrintData[i].makeIds[i].split("--");
                    // if(Array.isArray(splitArr) && splitArr.length && splitArr.length>1){
                    //     if(splitArr[1]=="false"){
                    //         labelPrintFlag = false;
                    //     }
                    // }
                    if(labelPrintData[i].id) {
                        // if(labelPrintData[i].labelEnabled){
                            let arr = [];
                            arr = arr.concat(GBK.encode('SIZE 50 mm , 70 mm\r\n'));
                            // arr = arr.concat(GBK.encode('SIZE 6.25,12.50\r\n'));
                            arr = arr.concat(GBK.encode('GAP 2 mm, 0 mm\r\n'));
                            // 
                            arr = arr.concat(GBK.encode('DENSITY 15\r\n'));
                            arr = arr.concat(GBK.encode('DIRECTION 0\r\n'));
                            arr = arr.concat(GBK.encode('SPEED 5\r\n'));
                            // 
                            arr = arr.concat(GBK.encode('CODEPAGE 437\r\n'));
                            arr = arr.concat(GBK.encode('BEEP\r\n'));
                            arr = arr.concat(GBK.encode("CLS\r\n"));
                            // start
                            // 座位号
                            let tableNo = data.tableNo;
                            // arr = arr.concat(GBK.encode("DENSITY 15\r\n"));
                            arr = arr.concat(GBK.encode('TEXT 15,30,"TSS24.BF2",0,1,1,'+`"Hello,座位号${tableNo?tableNo:"***"}的朋友`+'\r\n'));
                            // 品名
                            let goodsName =labelPrintData[i].productName;
                            arr = arr.concat(GBK.encode('TEXT 15,90,"TSS24.BF2",0,2,2,'+`"${goodsName}"`+'\r\n'));
                            // 二维码start
                            if(labelPrintData[i].hasOwnProperty("makeIds") && Array.isArray(labelPrintData[i].makeIds)){
                                arr = arr.concat(GBK.encode(`QRCODE 240,180,M,6,A,0,"${makeIdsArr[i]}"`+'\r\n'));
                            }
                            // 二维码end
                            if(labelPrintData[i].specs && Array.isArray(labelPrintData[i].specs) && labelPrintData[i].specs.length){
                                let specs = labelPrintData[i].specs.join("/");
                                arr = arr.concat(GBK.encode('TEXT 15,150,"TSS24.BF2",0,1,1,'+`"${specs}"`+'\r\n'));
                            }
                            if(labelPrintData[i].hasOwnProperty("codes") && codesArr[i] && String(codesArr[i])!="undefined" && String(codesArr[i])!="null"){
                                arr = arr.concat(GBK.encode('TEXT 15,210,"TSS24.BF2",0,2,2,'+`"${codesArr[i]}"`+'\r\n'));
                            }
                            let time = new Date(data.createTime).Format('yy-MM-dd hh:mm');
                            arr = arr.concat(GBK.encode('TEXT 15,280,"TSS24.BF2",0,1,1,'+`"${time}"`+'\r\n'));
                            arr = arr.concat(GBK.encode('TEXT 15,330,"TSS24.BF2",0,1,1,'+`"最佳尝味期不超过30分钟"`+'\r\n'));
                            if(labelPrintData[i].hasOwnProperty("tips") && Array.isArray(labelPrintData[i].tips) && labelPrintData[i].tips.length){
                                arr = arr.concat(GBK.encode('TEXT 15,380,"TSS24.BF2",0,1,1,'+`"${labelPrintData[i].tips[0]}"`+'\r\n'));
                                arr = arr.concat(GBK.encode('TEXT 15,420,"TSS24.BF2",0,1,1,'+`"${labelPrintData[i].tips[1]}"`+'\r\n'));
                            }else{
                                arr = arr.concat(GBK.encode('TEXT 15,380,"TSS24.BF2",0,1,1,'+`""`+'\r\n'));
                                arr = arr.concat(GBK.encode('TEXT 15,420,"TSS24.BF2",0,1,1,'+`""`+'\r\n'));
                            }
                            // 店铺名
                            let storeName = this.storeName.length>10?this.storeName.substring(0,9)+'...':this.storeName;
                            arr = arr.concat(GBK.encode('TEXT 15,470,"TSS24.BF2",0,1,1,'+`"${storeName}"`+'\r\n'));
                            
                            // 
                            arr = arr.concat(GBK.encode('TEXT 240,470,"TSS24.BF2",0,1,1,'+`"配送人:无"`+'\r\n'));
                            // 
                            
                            // arr = arr.concat(GBK.encode(`BARCODE 10,195,39,96,1,0,2,4,"123321"`+'\r\n'));
                            // // 此打印为当前订单的第几单
                            let nowCount = `${i+1}/${labelPrintData.length}`;
                            let notes = data.notes;
                            arr = arr.concat(GBK.encode('TEXT 15,510,"TSS24.BF2",0,1,1,'+`"杯数:${nowCount};${notes?('备注:'+notes):''}"`+'\r\n'));
                        // }
                            arr = arr.concat(GBK.encode('PRINT 1\r\n '));
                            // end
                            let testData = arr;
                            console.log(testData);
                            printForTag((localStorage.getItem('printIdForTag')?localStorage.getItem('printIdForTag'):''),testData);
                    }
                }
                
            }

        },
        surePrintForTag(data,labelPrintData){

            if(labelPrintData.length){
                console.log(labelPrintData)
                // 遍历商品数据
                for(let i=0;i<labelPrintData.length;i++){
                    console.log("dayil")
                    if(labelPrintData[i].id) {
                        // if(labelPrintData[i].labelEnabled){
                            let arr = [];
                            arr = arr.concat(GBK.encode('SIZE 40 mm , 30 mm\r\n'));
                            arr = arr.concat(GBK.encode('GAP 2 mm, 0 mm\r\n'));
                            // 
                            arr = arr.concat(GBK.encode('DENSITY 15\r\n'));
                            arr = arr.concat(GBK.encode('DIRECTION 0\r\n'));
                            arr = arr.concat(GBK.encode('SPEED 5\r\n'));
                            // 
                            arr = arr.concat(GBK.encode('CODEPAGE 437\r\n'));
                            arr = arr.concat(GBK.encode('BEEP\r\n'));
                            arr = arr.concat(GBK.encode("CLS\r\n"));
                            // arr = arr.concat(GBK.encode('TEXT 50,50,"TSS24.BF2",0,1,1,"你好"\r\n'));
                            // start
                            // 
                            if(labelPrintData[i].specs && Array.isArray(labelPrintData[i].specs) && labelPrintData[i].specs.length){
                                let specs = labelPrintData[i].specs.join("/");
                                // 座位号
                                let tableNo = data.tableNo;
                                // arr = arr.concat(GBK.encode("DENSITY 15\r\n"));
                                arr = arr.concat(GBK.encode('TEXT 10,10,"TSS24.BF2",0,1,1,'+`"座位号:${tableNo}"`+'\r\n'));
                                // arr = arr.concat(GBK.encode('TEXT 10,45,"TSS24.BF2",0,1,1,'+`"${tableNo}"`+'\r\n'));
                                // arr = arr.concat(GBK.encode('TEXT 10,45,"TSS24.BF2",0,1,1,'+`"${tableNo}"`+'\r\n'));
                                // 品名
                                let goodsName =labelPrintData[i].productName;
                                // arr = arr.concat(GBK.encode('TEXT 10,75,"TSS24.BF2",0,1,1,"品名:"\r\n'));
                                arr = arr.concat(GBK.encode('TEXT 10,50,"TSS24.BF2",0,1,1,'+`"品名:${goodsName}"`+'\r\n'));

                                // 规格
                                // arr = arr.concat(GBK.encode('TEXT 10,75,"TSS24.BF2",0,1,1,"品名:"\r\n'));
                                arr = arr.concat(GBK.encode('TEXT 10,88,"TSS24.BF2",0,1,1,'+`"规格:${specs}"`+'\r\n'));
                            }else{
                                // 店铺名
                                let storeName = this.storeName.length>9?this.storeName.substring(0,5)+'...':this.storeName;
                                arr = arr.concat(GBK.encode('TEXT 10,10,"TSS24.BF2",0,1,1,'+`"店铺名:${storeName}"`+'\r\n'));
                                // 座位号
                                let tableNo = data.tableNo;
                                // arr = arr.concat(GBK.encode("DENSITY 15\r\n"));
                                arr = arr.concat(GBK.encode('TEXT 10,50,"TSS24.BF2",0,1,1,'+`"座位号:${tableNo}"`+'\r\n'));
                                // arr = arr.concat(GBK.encode('TEXT 10,45,"TSS24.BF2",0,1,1,'+`"${tableNo}"`+'\r\n'));
                                // arr = arr.concat(GBK.encode('TEXT 10,45,"TSS24.BF2",0,1,1,'+`"${tableNo}"`+'\r\n'));
                                // 品名
                                let goodsName =labelPrintData[i].productName;
                                // arr = arr.concat(GBK.encode('TEXT 10,75,"TSS24.BF2",0,1,1,"品名:"\r\n'));
                                
                                arr = arr.concat(GBK.encode('TEXT 10,88,"TSS24.BF2",0,1,1,'+`"品名:${goodsName}"`+'\r\n'));
                            }
                            // 
                            // 价格
                            let price = (labelPrintData[i].salesPrice/labelPrintData[i].quantity).toFixed(2);
                            arr = arr.concat(GBK.encode('TEXT 10,125,"TSS24.BF2",0,1,1,'+`"价格:${price}元"`+'\r\n'));

                            // 时间
                            let time = new Date(data.createTime).Format('yy-MM-dd hh:mm');
                            arr = arr.concat(GBK.encode('TEXT 10,160,"TSS24.BF2",0,1,1,'+`"时间:${time}"`+'\r\n'));


                            // 此打印为当前订单的第几单
                            let nowCount = `${i+1}/${labelPrintData.length}`;
                            let notes = data.notes;
                            // 
                            arr = arr.concat(GBK.encode('TEXT 10,195,"TSS24.BF2",0,1,1,'+`"杯数:${nowCount};${notes?('备注:'+notes):''}"`+'\r\n'));
                            // 条形码start
                            // arr = arr.concat(GBK.encode(`QRCODE 20,20,L,4,A,0,"yaohao"`+'\r\n'));
                            // arr = arr.concat(GBK.encode(`BARCODE 10,195,39,96,1,0,2,4,"123321"`+'\r\n'));
                            // 条形码end
                        // }
                            arr = arr.concat(GBK.encode('PRINT 1\r\n '));
                            // end
                            let testData = arr;
                            console.log(testData);
                            printForTag((localStorage.getItem('printIdForTag')?localStorage.getItem('printIdForTag'):''),testData);
                    }
                }
                
            }
            
        },
        //硬代码
        surePrintForTagForMuXueHuangHou(data,labelPrintData){

            if(labelPrintData.length){
                console.log(labelPrintData)
                // 遍历商品数据
                for(let i=0;i<labelPrintData.length;i++){
                    console.log("dayil")
                    if(labelPrintData[i].id) {
                        // if(labelPrintData[i].labelEnabled){
                            let arr = [];
                            arr = arr.concat(GBK.encode('SIZE 40mm,30mm\r\n'));
                            arr = arr.concat(GBK.encode('GAP 2 mm, 0 mm\r\n'));
                            // 
                            arr = arr.concat(GBK.encode('DENSITY 15\r\n'));
                            arr = arr.concat(GBK.encode('DIRECTION 0\r\n'));
                            arr = arr.concat(GBK.encode('SPEED 5\r\n'));
                            // 
                            arr = arr.concat(GBK.encode('CODEPAGE 437\r\n'));
                            arr = arr.concat(GBK.encode('BEEP\r\n'));
                            arr = arr.concat(GBK.encode("CLS\r\n"));
                            // arr = arr.concat(GBK.encode('TEXT 50,50,"TSS24.BF2",0,1,1,"你好"\r\n'));
                            // 店铺名
                            let storeName = this.storeName.length>9?this.storeName.substring(0,5)+'...':this.storeName;
                            arr = arr.concat(GBK.encode('TEXT 10,20,"TSS24.BF2",0,1,1,'+`"店铺名:${storeName}"`+'\r\n'));
                            // 座位号
                            let tableNo = data.tableNo;
                            // arr = arr.concat(GBK.encode("DENSITY 15\r\n"));
                            // arr = arr.concat(GBK.encode('TEXT 10,50,"TSS24.BF2",0,1,1,'+`"座位号:${tableNo}"`+'\r\n'));
                            // arr = arr.concat(GBK.encode('TEXT 10,45,"TSS24.BF2",0,1,1,'+`"${tableNo}"`+'\r\n'));
                            // arr = arr.concat(GBK.encode('TEXT 10,45,"TSS24.BF2",0,1,1,'+`"${tableNo}"`+'\r\n'));
                            // 品名
                            let goodsName =labelPrintData[i].productName;
                            // arr = arr.concat(GBK.encode('TEXT 10,75,"TSS24.BF2",0,1,1,"品名:"\r\n'));
                            arr = arr.concat(GBK.encode('TEXT 10,80,"TSS24.BF2",0,1,1,'+`"品名:${goodsName}"`+'\r\n'));

                            // 价格
                            let price = (labelPrintData[i].salesPrice/labelPrintData[i].quantity).toFixed(2);
                            // arr = arr.concat(GBK.encode('TEXT 10,125,"TSS24.BF2",0,1,1,'+`"价格:${price}元"`+'\r\n'));

                            // 时间
                            let time = new Date(data.createTime).Format('yy-MM-dd hh:mm');
                            arr = arr.concat(GBK.encode('TEXT 10,140,"TSS24.BF2",0,1,1,'+`"时间:${time}"`+'\r\n'));


                            // 此打印为当前订单的第几单
                            let nowCount = `${i+1}/${labelPrintData.length}`;
                            let notes = data.notes;
                            arr = arr.concat(GBK.encode('TEXT 10,195,"TSS24.BF2",0,1,1,'+`"杯数:${nowCount};${notes?('备注:'+notes):''}"`+'\r\n'));
                        // }
                            arr = arr.concat(GBK.encode('PRINT 1\r\n '));
                            let testData = arr;
                            console.log(testData);
                            printForTag((localStorage.getItem('printIdForTag')?localStorage.getItem('printIdForTag'):''),testData);
                    }
                }
                
            }
            
        }, 
        // 
        sureKitchenPrint(){
            let kitchenPrintArr=[],newkitchenPrintArr=[],IskitchenPrint=false;

            let printArr = {};

            let hasOtherPrint = false;

            for(var i=0;i<this.printData.goodArr.length;i++){
                if(this.printData.goodArr[i].id) {
                    if(this.printData.goodArr[i].kitchenPrintEnabled){
                        
                        // 
                        if(this.printData.goodArr[i].ipAddress){
                            hasOtherPrint = true;
                            if(!printArr[this.printData.goodArr[i].ipAddress+"_"+this.printData.goodArr[i].port]){
                                printArr[this.printData.goodArr[i].ipAddress+"_"+this.printData.goodArr[i].port] = {};
                                printArr[this.printData.goodArr[i].ipAddress+"_"+this.printData.goodArr[i].port].printStr = [];
                                printArr[this.printData.goodArr[i].ipAddress+"_"+this.printData.goodArr[i].port].items = [];

                                printArr[this.printData.goodArr[i].ipAddress+"_"+this.printData.goodArr[i].port].items.push(this.printData.goodArr[i]);

                                // 
                                let newkitchenPrintArr=[];
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,66,9,1]);//蜂鸣提醒
                                newkitchenPrintArr = newkitchenPrintArr.concat([29,33,34]);//汉字倍宽高
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('座位号:：'+this.printData.tableNo));
                                newkitchenPrintArr = newkitchenPrintArr.concat([29,33,0]);//取消汉字倍宽高
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,1]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('下单人:：'+this.storeInfo.employeeName));
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('订单号:：'+this.code));
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('下单时间:：'+new Date(this.printData.createTime).Format('yyyy/MM/dd-hh:mm')));
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('打印时间:：'+new Date().Format('yyyy/MM/dd-hh:mm')));
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,1]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat([29,33,34]);//汉字倍宽高
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk(this.printData.goodArr[i].productName));
                                // 
                                if(this.printData.goodArr[i].specs && Array.isArray(this.printData.goodArr[i].specs) && this.printData.goodArr[i].specs.length){
                                    let specs = this.printData.goodArr[i].specs.join("/");
                                    newkitchenPrintArr = newkitchenPrintArr.concat(gbk("("+specs+")"));
                                }
                                // 
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('('+this.printData.goodArr[i].quantity+')份'));
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);//换行 
                                if(this.printData.goodArr[i].masterItemDtos && Array.isArray(this.printData.goodArr[i].masterItemDtos) && this.printData.goodArr[i].masterItemDtos.length){
                                    this.printData.goodArr[i].masterItemDtos.forEach(it=>{
                                        if(it.kitchenPrintEnabled){
                                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk('---配品:：'+it.productName));
                                            newkitchenPrintArr = newkitchenPrintArr.concat([10]);//换行
                                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk('---数量:：'+it.quantity));
                                            newkitchenPrintArr = newkitchenPrintArr.concat([10]);//换行                    
                                            // newkitchenPrintArr = newkitchenPrintArr.concat(gbk('---单价:：'+(it.salesPrice/it.quantity).toFixed(2)));
                                            newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                                        }
                                        
                                    });
                                }
                                newkitchenPrintArr = newkitchenPrintArr.concat([29,33,17]);//汉字倍宽高
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('备注:：'+this.printData.notes));
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat([29,86,0]);//切纸
                                if(parseInt(localStorage.getItem('kitchPrintCount'))===2){
                                    newkitchenPrintArr = newkitchenPrintArr.concat(newkitchenPrintArr);//默认两份
                                }else if(parseInt(localStorage.getItem('kitchPrintCount'))===0){
                                    newkitchenPrintArr = [];
                                }

                                printArr[this.printData.goodArr[i].ipAddress+"_"+this.printData.goodArr[i].port].printStr = newkitchenPrintArr;

                            }else{
                                printArr[this.printData.goodArr[i].ipAddress+"_"+this.printData.goodArr[i].port].items.push(this.printData.goodArr[i]);

                                // 
                                let newkitchenPrintArr=[];
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,66,9,1]);//蜂鸣提醒
                                newkitchenPrintArr = newkitchenPrintArr.concat([29,33,34]);//汉字倍宽高
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('座位号:：'+this.printData.tableNo));
                                newkitchenPrintArr = newkitchenPrintArr.concat([29,33,0]);//取消汉字倍宽高
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,1]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('下单人:：'+this.storeInfo.employeeName));
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('订单号:：'+this.code));
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('下单时间:：'+new Date(this.printData.createTime).Format('yyyy/MM/dd-hh:mm')));
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('打印时间:：'+new Date().Format('yyyy/MM/dd-hh:mm')));
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,1]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat([29,33,34]);//汉字倍宽高
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk(this.printData.goodArr[i].productName));
                                // 
                                if(this.printData.goodArr[i].specs && Array.isArray(this.printData.goodArr[i].specs) && this.printData.goodArr[i].specs.length){
                                    let specs = this.printData.goodArr[i].specs.join("/");
                                    newkitchenPrintArr = newkitchenPrintArr.concat(gbk("("+specs+")"));
                                }
                                // 
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('('+this.printData.goodArr[i].quantity+')份'));
                                newkitchenPrintArr = newkitchenPrintArr.concat([10]);//换行 
                                if(this.printData.goodArr[i].masterItemDtos && Array.isArray(this.printData.goodArr[i].masterItemDtos) && this.printData.goodArr[i].masterItemDtos.length){
                                    this.printData.goodArr[i].masterItemDtos.forEach(it=>{
                                        if(it.kitchenPrintEnabled){
                                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk('---配品:：'+it.productName));
                                            newkitchenPrintArr = newkitchenPrintArr.concat([10]);//换行
                                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk('---数量:：'+it.quantity));
                                            newkitchenPrintArr = newkitchenPrintArr.concat([10]);//换行                    
                                            // newkitchenPrintArr = newkitchenPrintArr.concat(gbk('---单价:：'+(it.salesPrice/it.quantity).toFixed(2)));
                                            newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                                        }
                                    });
                                }
                                newkitchenPrintArr = newkitchenPrintArr.concat([29,33,17]);//汉字倍宽高
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk('备注:：'+this.printData.notes));
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                                newkitchenPrintArr = newkitchenPrintArr.concat([29,86,0]);//切纸
                                if(parseInt(localStorage.getItem('kitchPrintCount'))===2){
                                    newkitchenPrintArr = newkitchenPrintArr.concat(newkitchenPrintArr);//默认两份
                                }else if(parseInt(localStorage.getItem('kitchPrintCount'))===0){
                                    newkitchenPrintArr = [];
                                }

                                let arr = printArr[this.printData.goodArr[i].ipAddress+"_"+this.printData.goodArr[i].port].printStr;
                                for(let k=0;k<newkitchenPrintArr.length;k++){
                                    arr.push(newkitchenPrintArr[k]);
                                }
                                // console.log(arr)
                                printArr[this.printData.goodArr[i].ipAddress+"_"+this.printData.goodArr[i].port].printStr = arr;

                            }
                        }else{
                            
                            // 
                            IskitchenPrint = true;
                            let newkitchenPrintArr=[];
                            newkitchenPrintArr = newkitchenPrintArr.concat([27,66,9,1]);//蜂鸣提醒
                            newkitchenPrintArr = newkitchenPrintArr.concat([29,33,34]);//汉字倍宽高
                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk('座位号:：'+this.printData.tableNo));
                            newkitchenPrintArr = newkitchenPrintArr.concat([29,33,0]);//取消汉字倍宽高
                            newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                            newkitchenPrintArr = newkitchenPrintArr.concat([27,100,1]);//空格走纸
                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk('下单人:：'+this.storeInfo.employeeName));
                            newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk('订单号:：'+this.code));
                            newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk('下单时间:：'+new Date(this.printData.createTime).Format('yyyy/MM/dd-hh:mm')));
                            newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk('打印时间:：'+new Date().Format('yyyy/MM/dd-hh:mm')));
                            newkitchenPrintArr = newkitchenPrintArr.concat([10]);
                            newkitchenPrintArr = newkitchenPrintArr.concat([27,100,1]);//空格走纸
                            newkitchenPrintArr = newkitchenPrintArr.concat([29,33,34]);//汉字倍宽高
                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk(this.printData.goodArr[i].productName));
                            // 
                            if(this.printData.goodArr[i].specs && Array.isArray(this.printData.goodArr[i].specs) && this.printData.goodArr[i].specs.length){
                                let specs = this.printData.goodArr[i].specs.join("/");
                                newkitchenPrintArr = newkitchenPrintArr.concat(gbk("("+specs+")"));
                            }
                            // 
                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk('('+this.printData.goodArr[i].quantity+')份'));
                            newkitchenPrintArr = newkitchenPrintArr.concat([10]);//换行 
                            if(this.printData.goodArr[i].masterItemDtos && Array.isArray(this.printData.goodArr[i].masterItemDtos) && this.printData.goodArr[i].masterItemDtos.length){
                                this.printData.goodArr[i].masterItemDtos.forEach(it=>{
                                    if(it.kitchenPrintEnabled){
                                        newkitchenPrintArr = newkitchenPrintArr.concat(gbk('---配品:：'+it.productName));
                                        newkitchenPrintArr = newkitchenPrintArr.concat([10]);//换行
                                        newkitchenPrintArr = newkitchenPrintArr.concat(gbk('---数量:：'+it.quantity));
                                        newkitchenPrintArr = newkitchenPrintArr.concat([10]);//换行                    
                                        // newkitchenPrintArr = newkitchenPrintArr.concat(gbk('---单价:：'+(it.salesPrice/it.quantity).toFixed(2)));
                                        newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                                    }
                                });
                            }
                            newkitchenPrintArr = newkitchenPrintArr.concat([29,33,17]);//汉字倍宽高
                            newkitchenPrintArr = newkitchenPrintArr.concat(gbk('备注:：'+this.printData.notes));
                            newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                            newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                            newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                            newkitchenPrintArr = newkitchenPrintArr.concat([27,100,2]);//空格走纸
                            newkitchenPrintArr = newkitchenPrintArr.concat([29,86,0]);//切纸
                            if(parseInt(localStorage.getItem('kitchPrintCount'))===2){
                                newkitchenPrintArr = newkitchenPrintArr.concat(newkitchenPrintArr);//默认两份
                            }else if(parseInt(localStorage.getItem('kitchPrintCount'))===0){
                                newkitchenPrintArr = [];
                            }
                            kitchenPrintArr = kitchenPrintArr.concat(newkitchenPrintArr);//默认两份
                                
                        }
                       
                    }
                }
            }
            if(IskitchenPrint){
                if(!localStorage.getItem('kitchIp')||!localStorage.getItem('kitchPort')){
                    alert('厨房打印失败！请设置IP和端口');
                    return;
                }
               
                printTcp_({ip:localStorage.getItem('kitchIp'),port:parseInt(localStorage.getItem('kitchPort'))}, kitchenPrintArr);
            }
            
            if(hasOtherPrint){
                for(let key in printArr){
                        
                    let ipInfo = key.split("_");
                    // console.log(this.printData.goodArr[i])
                    // printTcp_({ip:localStorage.getItem('kitchIp'),port:parseInt(localStorage.getItem('kitchPort'))}, kitchenPrintArr);
                    // printTcp_({ip:ipInfo[0],port:ipInfo[1]}, printArr[key].printStr);
                    // if(localStorage.getItem("kitchPrintMode") == "WholeOrder"){
                        // this.surePrintForkitchenOneType(printArr[key].items);
                    // }else{
                    printTcp_({ip:ipInfo[0],port:ipInfo[1]}, printArr[key].printStr);
                    // }
                    
                }
            }

        },
        // 计算总价
        calcAllPrice: function () {
            this.totalPrice = { // 选择商品总计
                number: 0, // 总数量
                allPrice: 0, // 总计金额
                salePrice: 0, // 优惠金额
                finalPrice: 0, // 最终价格
            }
            for (let i = 0, len = this.choiceArr.length; i < len; i++) {
                this.totalPrice.number += this.choiceArr[i].amount;
                this.totalPrice.allPrice += this.choiceArr[i].amount*this.choiceArr[i].salesPrice;
            }
            this.totalPrice.finalPrice = this.totalPrice.allPrice;
        },
        // 撤销订单
        delOrder: function () {
            if(!sessionStorage.getItem("ordersId")){
                this.$message({
                    message: "暂无订单",
                    showClose: true,
                    type: 'error'
                });
                this.showConfirmMask = false;
                return
            }
            this.$http.delete('orders/'+this.orderId).then((res)=>{
                this.$message({
                    message: "撤销成功",
                    showClose: true,
                    type: 'success'
                });
                this.orderId = '';
                this.curBindCoupon = []; // 清空选择的优惠券
                this.curSelCouponId = [];
                sessionStorage.removeItem("curSelectVipData");
                sessionStorage.removeItem("ordersId");
                // 传入index生成新订单
                this.showConfirmMask = false;
                this.clearOrder();
                this.getGoods();
                
                // 
                sessionStorage.removeItem("nowCurBindCoupon");
                sessionStorage.removeItem("nowSelCouponItem");
                // 
            });
        },
        // 查询订单状态
        searchOrderType: function () {
            this.$http.get('orders/' + this.orderId).then((res)=>{
                if(!res.data.id){
                    sessionStorage.removeItem("ordersId");
                    this.clearOrder();
                    return;
                }
                if ( this.newOrderStatus[res.data.status] ) {
                    sessionStorage.removeItem("ordersId");
                    this.clearOrder();
                }
            });
        },
        // 打开选择优惠券弹框
        openCoupon: function () {
            this.showPayLoding = true;
            console.log("choiceArr",this.choiceArr)//
            let choiceArrIds = [];
            if(this.choiceArr && Array.isArray(this.choiceArr) && this.choiceArr.length){
                this.choiceArr.forEach(it=>{
                    choiceArrIds.push(it.productId);
                })       
            }
            this.$http.get(this.curSelectVipData.id+'/coupon-instance?storeId='+this.storeId+'&page='+this.curCouponPage+'&size='+this.couponPageSize).then((res)=>{
                this.showPayLoding = false;
                if(res.data.couponInstances && Array.isArray(res.data.couponInstances) && res.data.couponInstances.length){
                    res.data.couponInstances.forEach(it=>{
                        let products = [];
                        if(it.productId){
                            let productIds = it.productId.split(",");
                            let productNames = it.productName.split(",");
                            if(productIds && Array.isArray(productIds) && productIds.length){
                                productIds.forEach((ite,ind)=>{
                                    if(choiceArrIds.indexOf(ite)!=-1){
                                        let obj = {
                                            productId:ite,
                                            productName:productNames[ind]
                                        }
                                        products.push(obj);
                                    }
                                })
                            }
                        }
                        
                        it.products = products;
                    })
                }
                console.log("res.data.couponInstances",res.data.couponInstances)
                this.couponList = res.data.couponInstances;
                if ( this.couponList && this.couponList[0] ) {
                    this.showSelCoupon = true;
                    // this.curCouponData = this.couponList[0];
                    this.curCouponIdx = -1;
                } else {
                    this.$message({
                        message: '暂无可用优惠券',
                        showClose: true,
                        type: 'error'
                    });
                }
            }).catch((err)=>{
                console.log("err",err)
                this.showPayLoding = false;
            })
        },
        selCouponItem(item,idx){
            this.curCouponData=item;
            this.curCouponIdx=idx;
            this.nowSelCouponItem = {};
            if(Array.isArray(item.products) && item.products.length==1){
                this.nowSelCouponItem = item.products[0];
            }
        },
        // 
        handleCommand(d){
            this.nowSelCouponItem = d;
        },
        // 选择优惠券
        choiceCoupon: function () {
            if(!this.orderId){
                this.$message({
                    message: '请先选择商品！',
                    showClose: true,
                    type: 'error'
                });
                return
            }
            if(this.curBindCoupon.length){
                this.$message({
                    message: '当前已经绑定优惠券。',
                    showClose: true,
                    type: 'error'
                });
                return;
            }
            let productId = "";
            try {
                if(this.curCouponData.products && Array.isArray(this.curCouponData.products) && this.curCouponData.products.length > 1){
                    if(!this.nowSelCouponItem || !this.nowSelCouponItem.productName){
                        this.$message({
                            message: '请选择优惠券所需抵扣的商品',
                            showClose: true,
                            type: 'error'
                        });
                        return;
                    }else{
                        productId = this.nowSelCouponItem.productId;
                    }
                }else{
                    let ids = this.curCouponData.productId.split(",")
                    if(ids.length > 1){
                        productId = this.curCouponData.products[0].productId;
                    }else{
                        productId = this.curCouponData.productId;
                    }
                }
            } catch (error) {
                this.$message.error("优惠券选择有误，无对应商品优惠。");
				return;
            }

            if(!this.canClick){
                return;
            }
            this.canClick = false;
            
            this.$http.put('orders/'+this.orderId+'/attachCouponInstance?couponInstanceCode='+this.curCouponData.code+"&productId="+productId).then((res)=>{
                setTimeout(()=>{
                    this.canClick = true;
                },500);
                this.curBindCoupon = res.data.couponInstances;
                this.showSelCoupon = false;

                let body = res.data;
                let items = body.items;
                let discountOrderItem = res.data.discountOrderItem;
                        
                for(let i=0;i<items.length;i++){
                    items[i].isDiscountForSecond = false;
                    for(let j=0;j<discountOrderItem.length;j++){
                        if(items[i].id == discountOrderItem[j].orderItem.id){
                            items[i].discountForSecondQty = discountOrderItem[j].qty;
                            items[i].isDiscountForSecond = true;
                        }
                    }
                }

                this.choiceArr = items;

                this.totalPrice = {
                    count:    res.data.count, // 总数量
                    total:    res.data.total, // 总计金额
                    discount: res.data.discount, // 优惠金额
                    amount:   res.data.amount, // 最终价格
                    removeZero:   res.data.removeZero, // 最终价格
                }
                this.$message({
                    message: '成功绑定优惠券',
                    showClose: true,
                    type: 'success'
                });
                let curSelCouponIdObj = {};
                curSelCouponIdObj.couponInstanceCode = this.curCouponData.code;
                this.curSelCouponId.push(curSelCouponIdObj);
                
                // 存入session
                sessionStorage.setItem("nowCurBindCoupon",JSON.stringify(this.curBindCoupon));
                sessionStorage.setItem("nowSelCouponItem",JSON.stringify(this.nowSelCouponItem));
                // 

            }).catch(()=>{
                setTimeout(()=>{
                    this.canClick = true;
                },500);
            })
        },
        // 解除优惠券
        relieveCoupon: function ( item ) {
            let productId = "";
            let nowSelCouponItem = sessionStorage.getItem("nowSelCouponItem") ? JSON.parse(sessionStorage.getItem("nowSelCouponItem")) : null;
            if(nowSelCouponItem && nowSelCouponItem.productId){
                productId = nowSelCouponItem.productId
            }else{
                productId = item.productId;
            }
            this.$http.put('orders/'+this.orderId+'/relieveCouponInstance?couponInstanceCode='+item.couponInstanceCode+"&productId="+productId).then((res)=>{
                this.curBindCoupon = res.data.couponInstances;
                let body = res.data;
                let items = body.items;
                let discountOrderItem = res.data.discountOrderItem;
                        
                for(let i=0;i<items.length;i++){
                    items[i].isDiscountForSecond = false;
                    for(let j=0;j<discountOrderItem.length;j++){
                        if(items[i].id == discountOrderItem[j].orderItem.id){
                            items[i].discountForSecondQty = discountOrderItem[j].qty;
                            items[i].isDiscountForSecond = true;
                        }
                    }
                }

                this.choiceArr = items;
                this.totalPrice = {
                    count:    res.data.count, // 总数量
                    total:    res.data.total, // 总计金额
                    discount: res.data.discount, // 优惠金额
                    amount:   res.data.amount, // 最终价格
                    removeZero:   res.data.removeZero, // 最终价格
                }
                console.log(item);
                let index;
                for(let i=0;i<this.curSelCouponId.length;i++){
                    let couponCode = this.curSelCouponId[i].couponInstanceCode;
                    if(couponCode === item.couponInstanceCode){
                        index = i;
                    }
                }
                if(index > -1){
                    this.curSelCouponId.splice(index,1);
                }
                console.log(index)
                sessionStorage.removeItem("nowSelCouponItem");
                console.log(this.curSelCouponId);
            }).catch(()=>{
                console.log(this.curSelCouponId);
            })
        },
        //挂起次单
        aNewOrder(){
            this.paymentBtn=true;
            this.showPayLoding = false;
            sessionStorage.removeItem("ordersId");
            clearInterval(this.payLoadTimer);
            this.clearOrder();
            this.getGoods();
        },
        //取消支付
        deletePayment( orderId ){
            if ( !this.canDeletepayment ) {
                return;
            } else {
                this.paymentBtn=true;
                clearInterval(this.payLoadTimer);

                if ( !this.delPaymentApiBtn ) {
                    return;
                }
                this.delPaymentApiBtn = false;
                this.$http.delete('payments/'+orderId).then((res)=>{
                    this.showPayLoding = false;
                    this.delPaymentApiBtn = true;
                    this.$message({
                        message: '取消支付成功！如果顾客已付款，系统会在24小时内将款项原路退回至顾客账户',
                        showClose: true,
                        duration:'15000'
                    });
                    window.location.reload(true);
                }).catch(()=>{
                    this.showPayLoding = false;
                    this.delPaymentApiBtn = true;
                })
            }
        },
        // 获取会员信息
        getMemberData: function ( memberId ) {
            this.$http.get(this.storeId+'/members?memberId='+memberId).then((res)=>{
                this.curSelectVipData = res.data;
                this.curSelectVipData.amount = this.curSelectVipData.amount.toFixed(2);
            });
        },
        getNotes(){
            this.$http({
                url:"get-msg",
                method:"GET",
                params:{
                    storeId:this.storeId
                }
            }).then(res=>{
                if(res.status == 200){
                    this.notesArr = res.data;
                    let selNotes = JSON.parse(localStorage.getItem("selNotes"));
                    if(selNotes && res.data.length){
                        this.notes = res.data[0].message;
                    }
                }
            });
        },
        changeArea(e){
            console.log(e);
            if(this.areas && Array.isArray(this.areas)){
                this.areas.forEach(it=>{
                    if(it.id == e){
                        this.tables = it.nums;
                        this.rentForm.numId = "";
                        this.rentForm.numName = "";
                    }
                })
            }
            this.$forceUpdate();
        },
        changeTable(e){
            if(this.tables && Array.isArray(this.tables)){
                this.tables.forEach(it=>{
                    if(it.id == e){
                        this.rentForm.numName = it.name;
                    }
                })
            }
            this.$forceUpdate();
        },
        getRegionList(){
            this.$http({
                url:"region/list",
                method:"POST",
                data:{
                    storeId:this.storeId
                }
            }).then(res=>{
                if(res.data && Array.isArray(res.data) && res.data.length){
                    this.areas = res.data;
                }
            })
        }
    },
    created(){
        this.getGoods();
        for (let i = 0; i < this.pageSize; i++) {
            this.choiceArr.push({});
        }
        if ( sessionStorage.getItem('ordersId') ) {
            this.orderId = sessionStorage.getItem('ordersId');
            this.$http.get('orders/'+this.orderId).then((res)=>{
                if(!res.data.id){
                    sessionStorage.removeItem("ordersId");
                    this.clearOrder();
                    return;
                }
                let body = res.data;
                this.curBindCoupon = body.couponInstances;
                this.code = body.code;
                if ( !body ) {
                    return;
                }
                let items = body.items;
                let discountOrderItem = res.data.discountOrderItem;
                        
                for(let i=0;i<items.length;i++){
                    items[i].isDiscountForSecond = false;
                    for(let j=0;j<discountOrderItem.length;j++){
//                         if(items[i].productId == discountOrderItem[j].productId){
                        if(items[i].id == discountOrderItem[j].orderItem.id){
                            items[i].discountForSecondQty = discountOrderItem[j].qty;
                            items[i].isDiscountForSecond = true;
                        }
                    }
                }

                this.choiceArr = items;
                this.totalPrice = {
                    count:    body.count, // 总数量
                    total:    body.total, // 总计金额
                    discount: body.discount, // 优惠金额
                    amount:   body.amount, // 最终价格
                    removeZero:   body.removeZero, // 最终价格
                }
                this.vipName = body.memberName;
                for (let i = 0, len = this.pageSize - this.choiceArr.length; i < len; i++) {
                    this.choiceArr.push({});
                }

                if ( res.data.memberId ) {
                    this.getMemberData(res.data.memberId);
                }
                //
                let nowCurBindCoupon = JSON.parse(sessionStorage.getItem('nowCurBindCoupon'));
                if(nowCurBindCoupon.length){
                    this.curBindCoupon = [];
                }
                //
            });
            // 如果用户刷新了界面，此时还原金额
            this.$http({
                url:"return-order",
                method:"POST",
                data:{
                    orderId:this.orderId
                }
            }).then(res=>{
                console.log(res);
                if(res.data.result.code == 200){
                    let body = res.data.data;

                    let items = body.items;
                    let discountOrderItem = res.data.discountOrderItem;
                            
                    for(let i=0;i<items.length;i++){
                        items[i].isDiscountForSecond = false;
                        for(let j=0;j<discountOrderItem.length;j++){
                            if(items[i].id == discountOrderItem[j].orderItem.id){
                                items[i].discountForSecondQty = discountOrderItem[j].qty;
                                items[i].isDiscountForSecond = true;
                            }
                        }
                    }

                    this.choiceArr = items;

                    this.totalPrice = {
                        count:    body.count, // 总数量
                        total:    body.total, // 总计金额
                        discount: body.discount, // 优惠金额
                        amount:   body.amount, // 最终价格
                        removeZero:   body.removeZero, // 最终价格
                    }
                }else if(res.data.result.code == 400){
                    this.clearOrder();
                }
            });
            this.relieveCoupon(nowCurBindCoupon);
        } else {
            // this.createdOrdersId();
        }
        if (sessionStorage.getItem('store')) {
            this.storeInfo = JSON.parse(sessionStorage.getItem('store'));
        };
        if ( localStorage.getItem('autoPrint')&&JSON.parse(localStorage.getItem('autoPrint')).placingOrder) {
            this.printsNum = JSON.parse(localStorage.getItem('autoPrint')).placingOrder;
        }
        // 获取充送规则
        this.$http.get('charge-rules?storeId='+this.storeId).then((res)=>{
            this.rulesData = res.data;
        })
    },
    mounted: function () {
        console.log("numberToChinese",this.convertCurrency("501.00"))
        try {
            this.getRegionList();
        } catch (error) {
            console.log(error);
        }
        $("#searchInput").focus();
        // this.showPayLoding = true;
        setTimeout(()=>{
            let endTime = new Date(JSON.parse(sessionStorage.getItem("endTime"))).getTime();
            let nowTime = new Date().getTime();
            console.log(endTime);
            if(nowTime>endTime){
                this.showMenu = false;
            }
            let endDay = Math.floor((endTime - nowTime) / ( 1000 * 60 * 60 * 24 ));
            console.log(endDay)
            this.endDay = endDay;


            let discount = JSON.parse(sessionStorage.getItem("discount"));
            let zero = JSON.parse(sessionStorage.getItem("zero"));
            this.showDiscount = discount;
            this.showZero = zero;

        },300);
        setTimeout(()=>{
            let chainEnabled = JSON.parse( sessionStorage.getItem("chainEnabled") );
            this.chainEnabled = chainEnabled;

            let allowProductCancelSale = JSON.parse( sessionStorage.getItem("allowProductCancelSale") );
            this.allowProductCancelSale = allowProductCancelSale;
        },1000);
        this.getNotes();
        let selNotes = JSON.parse(localStorage.getItem("selNotes"));
        if(!selNotes){
            this.selNotes = false;
        }else{
            this.selNotes = selNotes;
        }
        let leaseProductEnabled = sessionStorage.getItem("leaseProductEnabled")
        if(leaseProductEnabled == "true"){
            this.leaseProductEnabled = true;
        }else{
            this.leaseProductEnabled = false;
        }
    }
}
</script>
<style lang="scss" scoped>
    @import "cashier";
    .sel-item-wrap{
        .sel-item{
            .item-name{
                width:100%;
                font-weight:bold;
                font-size:16px;
                padding:10px 0;
            }
            .sel-cont{
                width:100%;
                display:flex;
                align-items:center;
                justify-content:space-between;
                flex-wrap:wrap;
                white-space:nowrap;
                .cont-item{
                    width:100%;
                    padding-bottom:15px;
                    .cont-name{
                        display:inline-block;
                        width:50px;
                    }
                }
            }
        }
    }
    .rent-wrap{
		.tit{
			font-size:18px;
			font-weight:bold;
			text-align:center;
		}
		.sel-item-wrap{
			padding:20px 0;
		}
		.rent-list{
			.rent-head{
				width:100%;
				height:40px;
				background:#059313;
				color:#fff;
				display:flex;
				align-items:center;
				.it{
					display:inline-block;
					text-align:center;
					width:50%;
				}
			}
			.rent-goods{
				background:#f4f4f4;
				.r-li{
					min-height:40px;
					width:100%;
					display:flex;
					flex-wrap:wrap;
					align-items:center;
					.it{
						width:50%;
						display:inline-block;
						text-align:center;
					}
				}
			}
		}
		.btns{
			padding:20px 0;
			.btn{
				width:100%;
				border-radius:5px;
				display:inline-block;
				text-align:center;
				line-height:40px;
				height:40px;
				background:#e66a6a;
				color:#fff;
				cursor:pointer;
			}
		}
	}
</style>
